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 trialsonam rathore
703 Pointswhat is wrong in this code?
its a challenge task 3/3 for try and except. something is wrong with the else part which i am unable to figure out. help me out with the solution. thanks
def add(num1,num2)
try:
return(float(num1)+float(num2))
except ValueError:
return(None)
else:
return(num1+num2)
add(2,3)
2 Answers
Alexander Davison
65,469 Points3 important errors:
- Your indentation is way off.
- You forgot a colon in front of
def add(num1, num2)
- There's no need for an else.
Fix all of that, your code should look like this:
def add(num1,num2):
try:
return float(num1) + float(num2)
except ValueError:
return None
Good luck! ~Alex
sonam rathore
703 Pointsthanks alex. the code worked. small mistakes though in my code.
Alexander Davison
65,469 PointsYour welcome :)