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 trialEmilio Andere
495 Pointswhy wrong
why is this wrong
add(467, 789)
def add(num1, num2):
try:
add = int(input("Sum of these two numbers?"))
except ValueError:
return(None)
else:
a = float(num1)
b = float(num2)
return(a + b)
2 Answers
Emilio Andere
495 Pointsstill cant
Steven Parker
231,275 PointsHere's a few hints:
- you only need to define the function for the challenge, you won't need to call it yourself
- the float conversions must be done inside the try section to catch the exceptions
- the arguments are passed directly to the function, so no input will be needed
Emilio Andere
495 Pointsdef add(num1, num2): try: a = float(num1) b = float(num2) add = int(input(num1 + num2)) except ValueError: return(None) else: return(a + b) ??????????
Emilio Andere
495 Pointsso what do I put inside add if It is not input?
Steven Parker
231,275 PointsI'm not sure what you intended to use the variable named "add" for, it doesn't seem to be related to the challenge. If you eliminate that line completely it looks like the new code might pass the challenge (I can't be sure because it is shown unformatted).
Use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Â Or watch this video on code formatting.
And would the person who down-voted my answer please explain why?