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 trialFrank Scarfone
Courses Plus Student 2,501 PointsI'm not sure what i'm doing wrong on this challenge.
I don't know if we were supposed to create an input to get the numbers? It doesn't say that we need to, but I can't get the correct answer here. If anyone can explain what i'm doing wrong, i'd appreciate it.
Thanksm
def add(one, two):
try:
one = float(one)
two = float(two)
except ValueError:
return ("None.")
else:
return (one + two)
ad = add(3,3)
print(ad)
1 Answer
Steven Parker
231,248 PointsYou're really close! Here are a few hints:
- for the challenge, just define the function, don't call it yourself
- you also won't need to print anything
- None is a special Python keyword. Don't add a period or put quotes around it (that makes it an ordinary string).
- FYI: you don't need parentheses after a return (but they don't hurt anything)
Frank Scarfone
Courses Plus Student 2,501 PointsFrank Scarfone
Courses Plus Student 2,501 Pointsahh! Thank you. I got it now.
Philip Ollas
5,705 PointsPhilip Ollas
5,705 PointsHi Steven, got the same error as Frank here but I'm not sure why since I've wrote it in the right manner
def add(one,two):
try:
numbers = float(one) + float(two)
except ValueError: return None else: return numbers