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 trial
Jerle Norton
905 PointsI'm having trouble with the squared coding exercise in Python basics. Any help would be greatly appreciated.
I can't seem to get it to work properly.
Steven Parker
243,658 Points... and a link to the challenge itself.
Jerle Norton
905 Pointshttps://teamtreehouse.com/library/python-basics/number-game-app/squared This is the link to the code challenge and this is what I have so far.
def squared(arg):
try:
return arg * arg
except TypeError:
if type(arg) == str:
return int(arg)
return len(arg) * arg
Jerle Norton
905 PointsThanks for the help, Courtney. I was kind of stuck there.
1 Answer
Courtney Jensen
1,882 PointsI think your error type is wrong. I had to play around with this for a long time, mine might be a complicated way of answering it but it worked! Mine looked like this:
def squared(num):
try:
return(int(num) ** 2)
except ValueError:
return(num * len(num))
Chris Freeman
Treehouse Moderator 68,468 PointsChanged to answer
Chris Freeman
Treehouse Moderator 68,468 PointsChris Freeman
Treehouse Moderator 68,468 Pointscan you post the code you've tried so far?