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 trialTrace Harris
Python Web Development Techdegree Graduate 22,065 Pointswhat is the correct syntax for try and except with two arguments that should return a float
Can someone take a look at my structure for this code challenge, I am not sure what is causing this challenge to fail.
def add(apple, orange):
try:
apple = int(input("please input a number"))
orange = int(input("please input a number"))
except ValueError:
return None
else:
return float(apple) + float(orange)
1 Answer
Trace Harris
Python Web Development Techdegree Graduate 22,065 PointsThanks I got it! I got messed up when I was trying to evaluate the arguments not the results. also to note that you do not need to declare a variable in the try block for the challenge to pass though it does make sense for dry purposes, the last expression in your block can be return final instead of repeating your expression.
sage georgi
2,005 Pointssage georgi
2,005 PointsThe problem is in your try and else statements.
you need to convert your apple and orange to floats in the try. You can scratch everything that is in the try right now. And instead copy and paste your else into your try like so
You can then return final in else the except stays in the middle as is though