Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

trial task 3

help please? trial task 3

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

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

    except ValueError:
        returne None

    return(number1 + number2)

1 Answer

Hi, there

Looking at your code you are very close!

Just some issues and mistake. First, this part from your code needs adjustment.

    try:

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

When you write try your code that is inside the try needs to be indented. Right now your two codes are not indented.

Second, the task want you to write else: so if you write else: before you write return (number1+number2) you will be spot on!

Hope this helps!

Thanks, still not getting though?

I copied your code and tried to do the challenge to see what else is wrong and I found a typo in your code. You wrote returne when it should have been return. Other than that, when I fixed your code like I mentioned it should let you pass the task.

thanks for all your help my code is still not passing can you please show me what its should look like?

Okay, Let me use your code and with comment it might be more helpful.

def add(number1, number2):
    try:
# the two codes should have an indent. Right now yours do not.
    number1 = float(number1)
    number2 = float(number2)
    except ValueError:
# you mispelled return it is  not returne! 
        returne None
# the task asks you to put else:
# also don't forget the indent return(number1 + number2) after you write else:
    return(number1 + number2)