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 (2015) Shopping List App Shopping List Introduction

Brecht Philips
Brecht Philips
8,863 Points

NameError: name 'apple' is not defined

Hi, I did everything from the video for the shopping list app but everytime i give in a string like apples or just a string i get a nameError when i give in 3 it works fine I'm coding in Pycharm from inteliJ

This is te code i have:

make a list to hold onto our items

shopping_list = []

print("What should we pick up at the store?") print("Enter 'DONE' to stop adding items.")

while True:

new_item = input("> ")
# be able to quit the app

if new_item == "DONE":
    break


shopping_list.append(new_item)

print("Here's your list: ") for item in shopping_list: print item

Brecht Philips
Brecht Philips
8,863 Points

hi again. I found my mistake in the console of pycharm if you mean a string for input you must put " " around the word.

Does anybody know why this is in inteliJ Java you didn't have to do it.

2 Answers

Scott Jones
Scott Jones
5,397 Points

FYI I had the same problem and found that if you go into the project settings >(name of project)>project interpreter> change the interpreter to python3 the problem is solved. Seems like my project was being interpreted as python2. Hope this helps someone!

Thank you! Ran into the same issue and realized that Mac OS X runs python2 as default

Mike Brooks
Mike Brooks
3,389 Points
while True:
    # ask for new items
    new_item = input("> ")

    # be able to quit app
    if new_item.upper() == 'DONE':
        break
    elif new_item.upper() == "HELP":
        show_help()
        continue
    elif new_item.upper() == "SHOW":
        show_list()
        continue

    # add new items to our list
    add_to_list(new_item)

show_list()

I did mine in pyCharm also and I do not see a difference

Brecht Philips
Brecht Philips
8,863 Points

Thanks for the answer i found the error it was if i insert an item without putting " " around it, it gave me an nameError but i was running python 2.7 i updated it to python 3.6 and now i can just type as input apple without the " " around it in the console