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! While you're at it, check out some resources Treehouse students have shared here.
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 trialLin Jyunsian
1,956 Pointswhat is the answer
what is the answer
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
def squared(value):
try:
if int(value) == True:
return value ** 2
except TypeError:
return value * len(value)
1 Answer
Taylor Schimek
19,318 PointsHowdy Lin,
First off, you don't need the if statement. Just TRY to return int(value) ** 2.
Secondly, you have the wrong error in the except. int() will take a string if the string is only of numbers, which it'll turn into an int. Therefore, TypeError isn't correct. Instead, try ValueError.