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 trial

Python Python Basics (2015) Logic in Python Try and Except

trial task 3

still not passing?

trial.py
def add(number1,number2):
    try:

    number1 = float(number1)
    number2 = float(number2)

    except ValueError:
        return None
    else:
    return(number1 + number2)

If you were confused about me saying indentation, I mean to say put 4 lines before where the code started.

Please note After : the following codes that are inside the function or method, must be indented in python.

See the : after try? Your two codes are not indented thus python will give you an error. The same goes with your return(number1 + number 2). It must be indented.

def add(number1,number2):
    try:
        number1 = float(number1)
        number2 = float(number2)

    except ValueError:
        return None
    else:
        return(number1 + number2)

1 Answer

Please look at my comment on your previous post. You still did not fix all the things I mentioned... The two codes after try are not indented.. You also need to indent the codes after else:

Thanks got it now!

Yay! I am glad I was able to help.

Sorry if you found my suggestions to be ambiguous, I tried to make things clear for you.