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 trialTiago Ramos
2,380 PointsI'm stuck in this task
I think I've done everything correctly can somebody tell me where's the error?
Thanks ;)
def squared(num):
# EXAMPLES
# squared(5) would return 25
try:
int(num)
return num * num
except ValueError:
return num * len(num)
# squared("2") would return 4
# squared("tim") would return "timtimtim"
1 Answer
James Shi
8,942 PointsThe line int(num) only checks if you can convert num to an integer. It doesn't change the variable num. Just change that line to num = int(num).
def squared(num):
# EXAMPLES
# squared(5) would return 25
try:
num = int(num) # change this line
return num * num
except ValueError:
return num * len(num)
# squared("2") would return 4
# squared("tim") would return "timtimtim"
Dean Meyer
1,378 PointsDean Meyer
1,378 Pointsdef add(Num1, Num2): try: Num1 = float(Num1) Num2 = float(Num2) return(Num1+Num2) except ValueError: return None else: print(Num1 + Num2)