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 trialJoel Corey
2,728 PointsTrial.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!
def add(arg1, arg2):
try:
return float(arg1) + float(arg2)
except ValueError:
return none
2 Answers
Alex Brown
3,555 PointsHi 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
Joel Corey
2,728 PointsLooks 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!