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 trialvvsr sashank
1,393 Pointswhat do I have to do in task 3?
def add(num1,num2): return float(num1)+float(num2)
def add(num1,num2):
try:
return float(num1)+float(num2)
except ValueError:
return None
else:
return None
vvsr sashank
1,393 Pointsdef add(num1,num2):
try: return float(num1)+float(num2)
except ValueError: return None
else: return None
2 Answers
Steven Parker
231,269 PointsNow you need a try block to allow the function to handle errors gracefully.
There's a good example of putting a try sequence together about 1 minute into the video The Exception to the Rule. The main difference in the challenge is that you won't be using print, just another return with a *None value.
You can leave your current return as-is, and you won't need the else.
Nicolas Bassano
2,125 PointsAs Steven said: the last else is not nedded
Plus, notice that you have an indentation problem on line 2 hence indentation problems for the rest of the code.
You were nearly there, keep at it.
BTW, the code should look like this.......
def add(num1,num2):
try:
return float(num1) + float(num2)
except ValueError:
return(None)
Nicolas Bassano
2,125 PointsNicolas Bassano
2,125 PointsHi!
mmmm I wonder how did you get to task 3??
Can you share the code for task 1 and 2?