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

Trial.py NameError: name 'add' is not defined

I have tried quite a few iterations, not sure what I am doing wrong but this challenge keeps erroring on NameError: name 'add' is not defined.

The following code runs just fine on my computerm, please excuse the horrible formatting with the pasted code:

def add(arg1, arg2): try: total = float(arg1) + float(arg2) except ValueError: return none else: return total

derp = add(2, 1) print(derp)

Thanks!

trial.py
def add(arg1, arg2):
  try:
    return float(arg1) + float(arg2)
  except ValueError:
    return none

2 Answers

Hi Joel,

It looks like you may have overthought the problem. All it is asking to simply return the sum of two numbers. You don't need to use any tries or excepts.

Here is my code for reference:

def add(x, y):
    return x + y

Looks like this double posted. The error was caused by not using a capital "N" in return none. Many thanks for the feedback though and I hope you have a great day!