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 trialEmilio Andere
495 Pointswhat is wrong now?
what is wrong here
def add(num1, num2):
try:
a = float(num1)
b = float(num2)
add = (num1 + num2)
except ValueError:
return(None)
else:
return(a + b)
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! You're really close here. There's only one line that's incorrect and it's this one:
add = (num1 + num2)
You started by trying to see if the num1
and num2
could be converted to numbers and then assigned them to a
and b
, but then you never did anything with a
and b
. Also, this code would try to take the numbers passed in and add them without first converting them and then assign them to a variable named add
, but that's what your function is named!
So if I switch out that line for this line:
return a + b
your code passes! Hope this helps!
Steven Parker
231,275 PointsDidn't you just ask another question about this?
As I said before, that line that creates the variable named "add" doesn't seem to be related to the challenge. If you eliminate that line completely you should pass the challenge (you don't need to replace it with anything).
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherSteven Parker is correct, you can remove the line and not replace it and pass. My line that I posted will work, but also gives you the option to erase the
else
clause at the end.