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 trialcharlesmonaghan
742 PointsI'm not sure what I'm doing wrong in this challenge?
Please don't give me the answer, just tell me what I'm doing wrong logically.
I'd still like to try my best to solve this specific challenge myself.
Any help is appreciated!
# 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 ValueError:
return num * len(num)
1 Answer
Steven Parker
231,236 PointsYou're really close! The "try" (and its colon) should be on a line by itself. The other stuff is already in the "return" formula and doesn't need to be done again anyway.
David Evans
10,490 PointsDavid Evans
10,490 PointsTo add on to this, give this video another look if you get stuck, they have a working example of the try/except: https://teamtreehouse.com/library/python-basics/number-game-app/number-game-refinement
Up voted this answer
charlesmonaghan
742 Pointscharlesmonaghan
742 PointsI changed it to this, but now it says "'squared' didn't return the right answer"?
charlesmonaghan
742 Pointscharlesmonaghan
742 PointsNvm! I fixed it, haha.