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 trialNoel Guerra
940 PointsFunctions: Float, Try, Except and Else
I followed step by step to my abilities, I think there should something else after the try block but I'm not certain what I'm doing wrong!
def add(whats, up):
try:
except ValueError
return None
else:
return float(whats) + float(up)
1 Answer
Elad Ohana
24,456 PointsHi Noel,
You're very close. The only thing that you have to change is the order of things. As written, your code asks to try something, but then doesn't state what to try. You can change your code to try
to return float(whats) + float(up)
and if it fails, return None
. Since you are converting your variables and returning the value at the same time, there isn't really a need for an else
, as your try
statement already performs all the functionality required in the challenge.
Take a look and good luck!
Elad
Noel Guerra
940 PointsNoel Guerra
940 PointsThanks Elad, i guess I misread the question and thought i needed an else