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 trialDaniel Holmes
2,765 Pointsneed help to pass this
def add(x, y): # number 1 and 2 return x + y # number 3 def add(x, y): f_x, f_y = float(x), float(y) return f_x + f_y def add(num1, num2): try: a = float(num1) # <-- indent b = float(num2) # <-- indent except ValueError: return None else: return(a + b)
I have been on this for 2 weeks need the code to move on for challenge 3
def add(x, y): # number 1 and 2
return x + y # number 3
def add(x, y):
f_x, f_y = float(x), float(y)
return f_x + f_y
def add(num1, num2): try: a = float(num1) # <-- indent b = float(num2) # <-- indent except ValueError: return None else: return(a + b)
4 Answers
Jennifer Nordell
Treehouse TeacherWell first off your add function is defined three times. It should only be defined once. At the end of step 2 my code looks like this:
def add (x,y):
return float(x) + float(y)
At the end of step 3 my code looks like this:
def add (x,y):
try:
return float(x) + float(y)
except ValueError:
return None
The only real difference between the two is to make sure the conversion to floats was successful.
Jennifer Nordell
Treehouse TeacherTry again. This code (which passed step 3) worked for me. Make sure nothing else is in there except these lines.
def add(x,y):
try:
return float(x) + float(y)
except ValueError:
return None
Daniel Holmes
2,765 Pointsthis code does not work for challege 3
Daniel Holmes
2,765 Pointsit still will not work