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 trialZachary Martin
3,545 PointsChallange 3/3 Try except
I looked in others with the same problem but I couldn't find the answer. Whats wrong with my code why won't it run?
def add (n1,n2):
try:
a = float(n1)
b = float(n2)
except ValueError:
return: None
else:
return(a+b)
add(2,3)
1 Answer
Cheo R
37,150 PointsHello Zachary, you're on the right track.
def add (n1,n2):
try:
a = float(n1)
b = float(n2)
except ValueError:
return: None
else:
return(a+b)
Just a few changes will get your code working:
- indent your code properly.
- No colons are needed after the return keyword.
def add (n1,n2):
try:
a = float(n1)
b = float(n2)
except ValueError:
return None
else:
return a+b
add(2,3)
Zachary Martin
3,545 PointsZachary Martin
3,545 PointsI've tried moving the floats and other things around from the standard nothing worked.