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 trialChristopher Johnson
2,066 PointsHelp with Try & Except challenge Task 3 of 3
I am not understanding what I am doing wrong here. I thought I added the try block where the question instructed me and correctly structured the loop. Any insight would be greatly appreciated
def add(num1, num2):
try:
return float(num1) + float(num2)
except ValueError:
return(None)
else:
return float(num1) + float(num2)
2 Answers
reanimator313
6,005 Pointsjust indent your code
def add(num1, num2):
# cod
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 PointsThere are two things.
- Your indents need correcting
- There is no need for the else statement, as there is no if statement.
def add(num1, num2):
try:
return float(num1) + float(num2)
except ValueError:
return(None)
Christopher Johnson
2,066 PointsThank you. I literally just figured out it was and indentation error. I appreciate you taking the time
Christopher Johnson
2,066 PointsChristopher Johnson
2,066 PointsI just figured out that was the error. Was driving me nuts. Thank you for the response