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 trialLaknath Gunathilake
1,860 Pointscant seem to get this exception to work
I'm not sure if I'm putting the try in the right place. It doesn't seem to work
def add (arg1,arg2):
try:
except ValueError:
return None
else:
return float(arg1)+float(arg2)
2 Answers
Steven Parker
231,269 Points
You have to indent both the try
and the else for them to be considered part of the function.
Also, you must attempt your float conversions inside the try block.
And, if you return inside the try, you won't need an else.
Laknath Gunathilake
1,860 PointsI indented both try and else but it doesn't seem to work