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 trialJim Garman
Python Web Development Techdegree Student 1,716 PointsProject 1: Challenge Task 3 - Exceptions
When checked, I get the message "Bummer! 'add' did not return the correct value". When I test this code in the Workspace and assign values to num1 and num2 and then PRINT the returned value of the function, it appears to work.
Any ideas what I am doing wrong? JG
def add(num1, num2):
try:
float(num1)
except ValueError:
return("None")
else:
try:
float(num2)
except ValueError:
return("None")
else:
return(float(num1) + float(num2))
3 Answers
Jon Mirow
9,864 PointsHi Felix!
No problems with your code, I just popped it in and it passed all three tests - try refreshing the page to reload the challenge and paste it in from your example here :)
Good job! :)
Jon Mirow
9,864 PointsHi there!
Ah so close! It really is a small thing - it wants you to return the python type None not the string "None",
return None
Will solve it Hope it helps :)
Jim Garman
Python Web Development Techdegree Student 1,716 PointsOh My! YES! Of course. Thank you!
Felix Ricart
Courses Plus Student 481 PointsI'm stuck on the same problem Jim was. My code is a little different and it works in another interpreter but not on workspace?? Anyone know what is wrong with this code? The error message I'm getting is: "NameError: name 'add' is not defined"
def add(x, y):
try:
x = float(x)
y = float(y)
except ValueError:
return None
else:
return x + y