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 trialSri lakshmi Kancherla
3,095 Pointsnot understanding what I am doing wrong in the code
Bummer! add
did not return the correct result.
not really getting what is wrong as its working in workspace.
thanks Sri
def add(num1,num2):
try:
total = float(num1) + float(num2)
except ValueError:
return()
else:
return(total)
4 Answers
Gabbie Metheny
33,778 PointsEverything looks great, just two slight tweaks are needed to your return
statements. You don't need the ()
for a return, and Kenneth wants you to explictly return None
in the except
block, using keyword None
. Then it should pass!
Sri lakshmi Kancherla
3,095 PointsHi all, I got it fix it , its only successful when I give return None and not return()
Thanks Sri
Keith Whatling
17,759 PointsYou are on the right track, two minor issues here.
Firstly, you have parenthesis on your return statements, this I think would return a tuple.
Secondly; the value error is returning a blank tuple, not None. None is a reserved word in python for being explicit about nothing.
def add(num1,num2):
try:
total = float(num1) + float(num2)
except ValueError:
return None
else:
return total
Manish Giri
16,266 PointsFor the except
block, you should return None
.
Sri lakshmi Kancherla
3,095 PointsSri lakshmi Kancherla
3,095 PointsHey thanks much , just got it .
Thank you Sri
Gabbie Metheny
33,778 PointsGabbie Metheny
33,778 PointsYou bet!