Welcome to the Treehouse Community
Looking to learn something new?
squared() function code challenge (no "else"?) [Solved]
The squared challenge mentions that you "might" not need the else block...
Here's my code
def squared(A_arg): try: num = int(A_arg) except ValueError: return(A_arg * len(A_arg)) else: return(num ** 2)
I just can't see how I could get around not using the else block without an error. Would it makes since (or even work)?
[MOD: added ```python markdown formatting -cf]
Ohhhh! I think I figured it out.
def squared(A_arg): try: num = int(A_arg) except ValueError: return(A_arg * len(A_arg)) return(num **2)
I think return ends the fuction. So i just put return(num ** 2) where the else block was and it worked! Sorry for the lack of indentation on my code. It was indented when I posted question.