Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
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.