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 trialbarrysw
2,110 Pointsquestion not understood ?? why is this not correct; see code
I seem to spend all of my time trying to understand the questions, the still seem to be written in a way that I can not comprehend.....
def add(arg1, arg2): try: float(arg1), float(arg2) except ValueError: return('None') else: return (float(arg1) + float(arg2))
def add(arg1, arg2):
try:
float(arg1), float(arg2)
except ValueError:
return('None')
else:
return (float(arg1) + float(arg2))
2 Answers
Seth Reece
32,867 PointsHi barrysw,
In your try block, you want to convert you args to float. You could do arg1 = float(arg1)
or total = float(arg1) + float(agr2)
Also, you don't need the extra parentheses in your return statement. return arg1 + arg2
should work fine if you convert them to floats in you try block.
Fabian George
Courses Plus Student 11,133 PointsHey barrysw,
I was having the same problem. Only thing you need to do to make your code work is to remove the parentheses and single quotes around the None.
def add(arg1, arg2):
try:
float(arg1), float(arg2)
except ValueError:
return None
else:
return (float(arg1) + float(arg2))