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 trialChase Alfrey
996 PointsTry and Except: Problem with Code
So, I was trying to do the last part of the last step: If you're following the structure from the videos, add an else: for your final return of the added floats. I got confused at the last part but I tried to do it anyway. I can't seem to figure out what's wrong with my code, though. Here's my code:
try:
def add(N1, N2):
N1 = float(N1)
N2 = float(N2)
except ValueError:
return None
else:
return(N1+N2)
1 Answer
Steven Parker
231,275 PointsEverything should be inside the function. That means the "def" line of the function will come first, and everything else that is part of it will be indented.
Chase Alfrey
996 PointsChase Alfrey
996 PointsThanks!