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 trialDidier Borel
2,837 Pointssquare of a number
i am not quite sure what I am doing wrong here
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
square=(number**2)
def number():
try :
int(input)
except ValueError:
return square
else: return (len(input)*len(input))
6 Answers
Idan Melamed
16,285 PointsHi Didier,
A few things.
- You don't need an input from the user. Assume the user will call the function with an argument like this "squared(5)"
- Inside "try:" you should try to return (the int value of the argument) ** 2
- If there is an error, return the argument * len(argument)
Try it a few times, and if you are still stuck I'll post my answer, ok?
Idan Melamed
16,285 PointsI found a simpler way... So I changed the steps above.
Didier Borel
2,837 Pointsthis iban
Idan Melamed
16,285 PointsDid you manage to find the answer?
Didier Borel
2,837 Pointsnot quite, still on it
Didier Borel
2,837 Pointsi have to catch a plane now, I probably won't be able to come back to this until next week, but thxs anyway.
Alex, your solution returns
"squared didn't return the right answer"