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 Introducing Lists Build an Application The Application

My list is not working...

When I add an item on the list, I get this NameError message: Traceback (most recent call last): File "shopping_list.py", line 11, in <module> new_item = input("> ") File "<string>", line 1, in <module> NameError: name 'water' is not defined

Here is my code:

def show_help():
    print("What should pick up at the store?")
    print("""
Enter 'DONE' to stop addding on the list.
Enter 'HELP' for this help.
""")

show_help()
while True:
    new_item = input("> ")
    if new_item == "DONE":
          break
    elif new_item == "HELP":
          show_help()
          continue
Josh Keenan
Josh Keenan
20,315 Points

Can you post the rest of your code, as that runs fine for me and the error points to line one, which isn't included here.

Also you don't need the continue at the bottom, it will just keep looping unless break is called.

3 Answers

With Python 2, you can use the raw_input function instead of the input function in your code to prevent the NameError. If you use Python 3, you can just use the input function.

ie. new_item = raw_input("> ") #works for python 2 ie. new_item = input("> ") #works for python 3

Just type: "Python3 shopping_list.py" in your terminal to run your programs with python3

I hope this helps!

Hi Josh! I copy/paste the code in my workspace and it worked. For some unknown reason, it doesn't work on my own text editor. I can't understand what is the difference, but thanks anyway :). I am happy to know that it actually works.

Matthew Hayes
Matthew Hayes
1,791 Points

I'm using WingIDE 101, It worked but i had to put 'HELP' or 'DONE' not HELP or DONE into the console for some reason. without the ' it just brought up the error.