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

having an error in this problem

can someone explain to me if this function need an input from a user or the define numbers only in the functions can you send me the right code for this one and some explanation thank you guys

trial.py
def add(num1,num2):
    try:
        n1 = float(num1)
        n2 = float(num2)

    except ValueError:
        return()

    else:
        return(n1+n2)

1 Answer

Steven Parker
Steven Parker
231,248 Points

:point_right: Actually, your code is fine as it is, except that you forgot to return the value "None" in the case of an error:

    except ValueError:
        return(None)

After making that one change, you will pass the challenge.

Russell is partly right in that you don't need parentheses with return, and I would recommend omitting them, but they don't hurt anything.

I think you made a good choice in using different variables for the converted float values, it makes your code easier to read. :+1: I would consider that a programming "best practice".

sp:sparkles:

tnx for the help guys got it