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

christianfigueroa
christianfigueroa
13,595 Points

I'm getting an error say 'add' not defined

Not sure why its spitting out this error.

trial.py
def add(x,y):
  try:
    return float(x)+float(y)
  except ValueError:
    return none
  else:
    return float(x)+float(y)

2 Answers

Actually it is returning none when it should be None

Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

Thanks jcorum

I caught that just as I hit Post! Edited my answer to reflect the correct term. :)

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Christian,

It seems like a weird error to be spitting out considering that it's just a small typo that is throwing it... but I guess that's coding for you.

The return in your except clause is returning none with a lower case 'n' when it should be None with an uppercase 'N'

Just fix that up and you're good to go. :dizzy:

EDITED: Was using 'true/True' instead of 'none/None' in my reply. That was my misreading. Sorry

christianfigueroa
christianfigueroa
13,595 Points

Thanks a bunch for your help! now i can continue learning Python =D