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 trialGeet Aneja
811 Pointsdef add(x,y): try: x = float(input("Tell me a number")) y = float(input("Tell me another number"))
What's wrong here?
def add(x,y):
try:
x = float(input("Tell me a number"))
y = float(input("Tell me another number"))
except ValueError
return None
x = float(x)
y = float(y)
else:
return (x+y)
1 Answer
Steven Parker
231,236 PointsYou have a few issues here:
- you don't need any input statements, just work with the supplied arguments
- check your indentation - everything inside the function must be indented
- a
try
,except
andelse
set must all be indented the same amount - an
except
statement requires a colon at the end - you won't need to do the float conversions twice, just once inside the
try
Ben Slivinn
10,156 PointsBen Slivinn
10,156 PointsIm sorry, but i can't understand the logic of your code, it will be better if you could explain it, and tell me what the intention of the program. what should the program do?
but until then:
Don't foger ':' in the except.
except ValueError:
if the 'return None' is a part of 'except' so move it one tab fwd.
The 'else' should be part of "try/except" so you should move it one tab fwd.
i can't see why you use
again inside the function, if when you ask for user input you used the float function to make sure the input is float type.