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 trialOmari Wright
1,475 Pointswhy is this code not working? I cant move on when I am stuck! def add(num1, num2): return float(num1 + num2)
https://teamtreehouse.com/library/python-basics/logic-in-python/try-and-except
so what is the problem with this?
def add(num1, num2):
return float(num1 + num2)
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! I can only assume that you are working on step 2 as your code passes Step 1 just fine. However, in Step 2 it says to turn them into floats before you add them. Remember, you have no idea what they're sending in. They might send in 21 and "Hello!". One can be converted to a float, but the other one can't.
Here's what my return statement would look like for Step 2:
return float(num1) + float(num2)
This code takes each number individually and turns it into a float (or fails with a ValueError) then it adds them and returns the result.
Hope this helps!