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 trialAdam Marasli-Zaade
2,966 PointsSolved it yesterday, I am trying to solve it today as well but I keep doing something wrong for some reason.
def add(a, b,):
try:
return(float(a) + float(b))
except ValueError:
return None
else:
return(float(a) + float(b))
? thnx :)
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! Your code and logic are fine. The syntax is spot on. However, the indentation is incorrect. The declaration of the of the method begins a block. Everything after must be indented to be a part of this block. So, if I simply rework your indentation, it passes the last step.
def add(a, b,):
try:
return(float(a) + float(b))
except ValueError:
return None
else:
return(float(a) + float(b))
Keep in mind, this is your code, only properly indented! Hope this helps!
Diar Selimi
1,341 Pointsmaybe you wan't to call your defined function in the first return like return add(param1, param2)
def add(a, b,):
try:
return add(float(1), float(2))
except SomeException as exception:
return null
finally:
return something
Sneha Nagpaul
10,124 PointsSneha Nagpaul
10,124 PointsI don't understand the else statement in this code. Isn't it redundant?
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherYes, Sneha Nagpaul. It is redundant and not needed at all. In fact, the instructions on step 3 hint at this. There is some part in the video where they use the else statement so in step 3 you'll see this:
But, in reality, the else statement can be removed entirely