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 Functions and Looping Returning Values

Hi everybody! I wrote the code exactly like it was in the video until 4.46 and is not working for me. Please Help!

It's giving me: NameError: split_check not defined

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

When I see an error like that it means you might have forgotten to define split_check() before you tried to use it

This can happen if you try to call to split_check() before it was defined or imported. Here I type in to the Python REPL (command interpreter) launched from the command line and you can see the error.

PS C:\Users\jeff> python
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> # If I try to use split_check before it is defined... see error below.
>>> print(split_check(35.22, 2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'split_check' is not defined
>>> # now, I type the function in to define it... 
>>> def split_check(total, number_of_people):
...     cost_per_person = total / number_of_people
...     return cost_per_person
...
>>> # now, it will work.
>>> print(split_check(35.22, 2))
17.61
>>>

Thank you very much Jeff that was really helpful!