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


shopping_list.py error '<item-name>' is not defined

I'm having this error while doing this shopping_list.py exercise:

     Traceback (most recent call last):
       File "shopping.py", line 7, in <module>
         new_item = input('> ')
       File "<string>", line 1, in <module>
     NameError: name 'Apples' is not defined

This came out after adding Apples to the list, any thoughts? Here's is my code:

    shopping_list = list()

    print("What should we pick up?")
    print("Enter DONE to stop adding items")

    while True:
        new_item = input('> ')

        if new_item == "DONE":

        print("Added! List has {} items".format(len(shopping_list)))

    print("Here is your list:")

    for item in shopping_list:

1 Answer

ok apparently you must be using python <filename> not python3.. i.e the code relates to python 3.. there is a slight difference to how you get inputs in python2..

new_item = raw_input("please enter something: ")

Thank you very much! I will have this always in mind.