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

Can't understand the error.

I don't get the error.

trial.py
def add(add1,add2):
    try:
        add1 = int(input("Enter first num: "))
        add2 = int(input("Enter second num: "))           
        except ValueError:
            return(None)
        else:
            return(float(add1) + float(add2))

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Andrej,

The challenge does not ask you to input anything. The arguments add1 and add2 will be passed into the function for you to use as is. You are essentially overwriting them.

The challenge is asking you to do the following:

1) Try to convert add1 and add2 into floats.

2) If they can't be converted (i.e. they throw a ValueError), return None.

3) Otherwise, return the sum of add1 and add2

Also, be very careful of your indentation. The except block should not be inside your try block. Same goes for the else statement.

Good luck.