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 trialAlejandro Byrne
2,562 PointsWhy am I getting the error, "Bummer! 'squared' did not return the right answer!"?
I don't know how to fix my code... I've revised it multiple times and can't seem to find the solution. Can someone help? I'm supposed to make a function called 'squared' and try to turn the num into an int and square it, if it can't, then square the length of the string.
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
def squared(num):
try:
num = int(num)
return(num ** 2)
except ValueError:
return(len(num) ** 2)
1 Answer
Robert Lyon
7,551 PointsYou are really close to the answer here but the question is not asking you to square the length of the string. I is asking you to multiply the string by it's length.
return num * len(num)
hope this helps
Alejandro Byrne
2,562 PointsAlejandro Byrne
2,562 PointsYep. Thanks, it worked!