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 trialNicolas Cortinas
691 PointsI dont see what I am missing here
Hello,
I have been trying to complete this task but I cant see what I am missing, maybe you can give me a hand!
Thank you very much!
Nico.
def add(num1, num2):
try:
return(float(num1) + float(num2))
except ValueError:
return = None
else:
return(float(num1) + float(num2))
2 Answers
Alexander Davison
65,469 PointsLike what Ted Dunn said, you must indent the code that is part of the try
block.
But, also, you should be assigning a brand-new variable called return
to the value of True
(that's what Python is thinking you want to do), but returning the value.
Lastly, I just want to point out that there's no need to the else
clause. The try
block will automatically do that if it doesn't cause an error (the try block actually runs the code, not just tests and see if it causes an error. However, if it does cause an error, it moves into the except
part. Some people didn't know that, and that's an important understanding.)
If you fix those, you should end up with:
def add(num1, num2):
try:
return(float(num1) + float(num2))
except ValueError:
return None
I hope you understand :)
Good luck! ~alex
Ted Dunn
43,783 PointsYour first return statement (in the try block) needs to be indented.
Nicolas Cortinas
691 PointsThank you very much, Ted! I solved it
Nicolas Cortinas
691 PointsNicolas Cortinas
691 PointsThank you Alex! It really helped me out! Now I know something new! thanks!!