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

NameError stuck and do not know why?????

its saying i did not define add??????

trial.py
def add(Days, months):
    try:
        Days = float(Days)
        months = float(months)
    except ValueError:
        return none
    else:    
        return (Days + months)

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! This Bummer message is a bit odd. If you run your code in the workspace (or on your local system) and try and call the add function and send in arguments like (2, "hello"), when it hits the ValueError, it triggers a NameError on none saying that it isn't defined.

Much like the reserved words True and False in Python, the reserved word None must also be capitalized. Right now it's looking for a variable named none which it can't find.

You wrote:

return none

But that should be:

return None

Hope this helps! :sparkles:

You're so close! 'None' underneath your except ValueError needs to be capitalized.