Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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.