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 trialDeron Gomez
Courses Plus Student 2,571 PointsFrustrated..
def add(x, y): try: a = float(x) b = float(y) except ValueError: return None else: return a + b
so tell me whats wrong with this one..........
def add(x, y):
try:
a = float(x)
b = float(y)
except ValueError:
return None
else:
return a + b
1 Answer
Paul Harrison
5,533 PointsHey Deron -
Because the variables "a" and "b" are assigned in the try, but they're only combined and returned in the "else", this code won't complete the challenge. If you add the "return a + b" to the try, it should work. Unless you're expecting odd input and need the validation, there isn't really a need to do a try/except/else.
Alternatively, this code will work:
def add(x, y):
return x + y
Deron Gomez
Courses Plus Student 2,571 PointsDeron Gomez
Courses Plus Student 2,571 Pointsok thanks!