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 trialChristopher Parke
21,978 PointsI put this code in a test pad on another site and it runs just fine. I put it in this workspace and I get "bummer"
What's wrong with this? I put this in https://coderpad.io/KHDMGCDN and it works fine.
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
def squared(square):
try:
if square == int(square):
square = square ** 2
print(square)
except ValueError:
square = square * len(square)
print(square)
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsThere are two errors. The challenge asks to return
the values not print them. Also the code checks if squared
is an int
but don't convert it if it is an int
:
def squared(square):
try:
return int(square) ** 2
except ValueError:
return square * len(square)