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 trialCarole Cox
429 Pointslooks good but its not...
Not sure about the final return, should it be return (num) with an num=num1+num2 or does return num1+num2 handle that? ORRRRR should it be return (num1+num2). Why's and why's not? Thank you!
def add(num1,num2):
try:
num1=float(num1)
num2=float(num2)
except ValueError:
return None
else:
return (num1 +num2)
2 Answers
William Li
Courses Plus Student 26,868 PointsHi there.
Your code is fine, what prevents it from passing is the indentation, you see, indentation is a big part of Python's syntax.
def add(num1, num2):
try:
num1=float(num1)
num2=float(num2)
except ValueError:
return None
else:
return (num1 +num2)
Shift the indentation of all lines of your code after line 1 one level to the right, and now it should be fine.
Carole Cox
429 PointsThanks William!
Yes, once I got it all lined up...it worked. Took me a sec. NEWBIE MISTAKES! Its getting better...