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 trialEmmett Armstrong
3,794 Pointsint(num)?
This challenge is not giving me useful error messages. It simply says "try again", without telling me anything about what is wrong or how to fix it.
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
def squared(num):
try int(num):
return int(num) ** 2
except TypeError:
return num * len(num)
seekwiser
2,127 PointsI fully agree with you on the try again errors. they just don't help. anyway your return for the except isn't right as the objective is asking for you to return a string. can you multiply a string to a number and get a output of string+string+string? i haven't tried to be honest.
1 Answer
Emmett Armstrong
3,794 PointsThank you! I ended up finding my errors by dropping my code into Workspaces and running in the terminal.
Julio Garcia
1,944 PointsJulio Garcia
1,944 PointsYou have 2 Errors: 1.- You don't need to pass anything to the try exception. Remove the int(num) from try 2.- In the except call is not looking for a TypeError is looking for a ValueError.
Change that two error and check it again.