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 trialilya A
3,802 PointsWhat am I doing wrong?
I have tried everything...
def add (scooby, doo):
try:
return float(scooby) + float(doo)
except ValueError:
return(None)
else:
return(float(scooby) + float(doo))
3 Answers
Jonathan Corona
716 PointsI spent the last hour working on the same exact problem, hopefully this will help you with syntax:
def add(scooby, doo):
try:
return(float(scooby) + float(doo))
except ValueError:
return None
You do not need an else statement if you have two returns. You're main issue was that you did not have the proper indents and you you needed more parenthesis a la: return(float(scooby) + float(doo)).
Steven Parker
231,269 PointsIt looks like you need to adjust your indentation a bit:
- everything that is part of a function must be indented more than the "def" line
- a "try", "except" and "else" must all be indented the same amount (they must line up)
- anything that is part of those must be indented more
Also, you won't need an "else" if both the "try" and "except" perform a "return".
I'l bet you can get it now without an explicit spoiler.
Jonathan Corona
716 PointsThank you, it didn't fail me on my answer so I would not have none that about the parenthesis unless you had mentioned it.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsThe parentheses around the entire return expression are actually not necessary (but they don't hurt).