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 trialJoshua Senneff
1,159 PointsI don't get what's wrong, using try and except to times a string by the number of letters in it
Please help, I don't get whats wrong
def squared(num):
try:
int(num)
num *= num
return num
except ValueError:
list_num = list(num)
num *= len(list_num)
return num
1 Answer
Henrik Christensen
Python Web Development Techdegree Student 38,322 Pointsdef squared(num):
try:
return int(num) * int(num) # here you convert num to an int and return at the same time
except ValueError:
return num * len(num) # if cannot convert then multiply num by the length of num
Joshua Senneff
1,159 PointsJoshua Senneff
1,159 PointsAh Ok, I think I get it now. You have to get the original num instead of a list of it, Thank you!