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 trialThomas Beaudry
29,084 PointsSomething is not right, this is part 3 of "Try and Except"
Add a try block before where you turn your arguments into floats.
Then add an except to catch the possible ValueError, inside the except block.
Add an else for your final return.
def add(arg1, arg2):
try:
test = float(arg1) + float(arg2)
except ValueError:
return(none)
else:
return(float(arg1) + float(arg2))
3 Answers
Kevin Li
2,634 PointsHi, This code should work. I think you should just add them in the try block before returning them.
def add(num1, num2):
try:
float(num1) + float(num2)
except ValueError:
return None
else:
return float(num1) + float(num2)
Jarred Miles
22,560 PointsYour code is right you just added () after return when they are not needed. Your code should look like this.
def add(num1, num2):
try:
float(num1) + float(num2)
except ValueError:
return None
else:
return float(num1) + float(num2)
Thomas Beaudry
29,084 PointsJarred, I tried your code without the () but it's still showing "Bummer! Try again!)
Jarred Miles
22,560 PointsOh yeah, my bad I did this real quick I see my error. >.< I'm glad you got your question answered though!
Thomas Beaudry
29,084 PointsJarred Miles, thanks for ur input, glad you tried to help out, happy coding :)
Thomas Beaudry
29,084 PointsHello Kevin Li, Yes, you got it, I should have just added them in the try block before returning. Your right it did work! Wow, I've been on this code challenge since Friday! You are THE MAN...thank you so much! :)
Kevin Li
2,634 PointsYeah... no problem. I remember I was stuck on that for a week.