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 trialKarol Zientek
2,006 PointsCan't solve the Python challenge! Challenge Try and Except 3rd Task
I can't solve the third task of this challenge, could anyone helm me? Just tell me what is wrong in my challenge, please.
def add(n1,n2):
try:
return float(n1) + float(n2)
except ValueError:
return (None)
else:
return float(n1) + float(n2)
1 Answer
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Karol
In your try block just convert the arguments to floats. In the else block return the sum of the arguments. See below
def add(num1,num2):
try:
num1 = float(num1)
num2 = float(num2)
except ValueError:
return None
else:
return num1 + num2
Karol Zientek
2,006 PointsKarol Zientek
2,006 PointsThanks it worked, mate! I really appreciate it!