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

Functions: Float, Try, Except and Else

I followed step by step to my abilities, I think there should something else after the try block but I'm not certain what I'm doing wrong!

def add(whats, up): 
    except ValueError
        return None
        return float(whats) + float(up)

1 Answer

Elad Ohana
Elad Ohana
24,456 Points

Hi Noel,

You're very close. The only thing that you have to change is the order of things. As written, your code asks to try something, but then doesn't state what to try. You can change your code to try to return float(whats) + float(up) and if it fails, return None. Since you are converting your variables and returning the value at the same time, there isn't really a need for an else, as your try statement already performs all the functionality required in the challenge.

Take a look and good luck!


Thanks Elad, i guess I misread the question and thought i needed an else