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 trialjasmar
1,059 PointsWhy is this simple bit of code wrong?
I'm not sure why this setup doesn't work. Any input?
def squared(arg):
try:
return arg * arg
except:
return arg * len(arg)
3 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsThe challenge asks you to try converting the argument to an int
before squaring. Wrap each arg
in int()
Dan Garrison
22,457 PointsHere's a hint. The argument entered into the function can either be an integer or a string. In order to multiply a number together, it needs to be turned into an integer. So this is what you should try first. If it fails to turn the argument into an integer then that is where the exception statement will run.
jasmar
1,059 PointsThanks!