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 trialvikram choudermet
5,701 Pointsit"s showing error,try again
def add(num1,num2): try: A= float (num1) B= float (num2) except ValueError: return none else: return A+B
def add(num1,num2):
try:
A= float (num1)
B= float (num2)
except ValueError:
return none
else:
return A+B
1 Answer
Ryan S
27,276 PointsHi Vikram,
Your logic is correct, however there are two things you'll need to fix.
First, the keyword "none" needs to be capitalized. You'll notice with the challenge editor (and most text editors) that python keywords will change to a different color than variables, for example. This is useful way to quickly find syntax errors.
Second, it is good practice (and necessary with Python) to have consistent indentation. Your code above is not aligned properly and even if you fix the "None" keyword, you will still get an error. Try sticking to 4 spaces for your tabbed indentation.
def add(num1, num2):
try:
A = float(num1)
B = float(num2)
except ValueError:
return None
else:
return A + B
Hope this helps.