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

Why this is showing error?

Why task 3 is showing error?

trial.py
def add(n1,n2):
    try:
        add=float(input("Enter number"))
    except ValueError:
        print("Thats not a  number")
        return None
    else:
    return float(n1)+float(n2)

1 Answer

Stuart Wright
Stuart Wright
41,120 Points

I think you've misunderstood the question. You are not supposed to request input from the user. The input to the function will be n1 and n2. You should try to convert n1 and n2 to float, and if successful, return the converted n1+n2. If you encounter a ValueError, return None instead.