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 trialtom shennan
1,718 PointsWhat's wrong with my code??
Hey guys, I've been stuck on this challenge for a bit now, I can't figure out what's wrong with what I've done, any help will be appreciated, thanks.
def add(x, y):
try:
arg1 = float(x)
arg2 = float(y)
except ValueError:
return None
else:
return (arg1 + arg2)
1 Answer
andren
28,558 PointsYour code is correct syntax wise, but the indentation (horizontal spacing) is incorrect. In Python indentation is used to group code and it is essential to get it right. Since the try/except/else
blocks are supposed to be a part of the add
function they have to be indented to be inside of it.
If you fix the indentation like this:
def add(x, y):
try:
arg1 = float(x)
arg2 = float(y)
except ValueError:
return None
else:
return (arg1 + arg2)
Then your code will work.
tom shennan
1,718 Pointstom shennan
1,718 PointsThank you so much!