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 trialnicholas Christie
433 Pointswhat's wrong?
?
def add(always,win):
try:
add=int(input("Give me a argument: "))
except ValueError:
return(None)
first_num= float (always)
second_num= float(win)
else:
return(first_num+second_num)
1 Answer
Steven Parker
231,275 PointsHere are a few hints:
- everything that is part of a function must be indented more than the "def" line
- a "try" and its corresponding "except" (and optional "else") must all be indented the same amount
- this function should use the arguments passed in, it won't need to "input" anything
- to be able to detect conversion errors, the conversions must be inside the "try" block
nicholas Christie
433 Pointsnicholas Christie
433 Pointsplayed around with it took out int and input wasn't really sure what to do in the try block I put try: add="always,win" return(None) first_num= float(always) second_num=float(win) else: return (first_num+second_num)
Steven Parker
231,275 PointsSteven Parker
231,275 PointsIt's hard to see what's happening there without indentation. When posting code, 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.
Even without formatting, this line doesn't seem to make sense
add="always,win"
Also the "except" seems to be missing.