Python Python Basics (2015) Shopping List App Shopping List Introduction

Ross Thompson
Ross Thompson
7,706 Points

I'm getting a NameError unless my input is typed as a String. Even when I copy & paste the exact same code in video

code :shopping_list = []

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

while True:

new_item = input("> ")

if new_item == 'DONE':
    break

shopping_list.append(new_item)

print("Here's your list:")

for item in shopping_list: print(item)

2 Answers

Ryan S
Ryan S
27,260 Points

Hi Ross,

It sounds like you are using Python 2. If so, you will need to use the raw_input() function instead.

input() does not work the same in Python 2 as Python 3.

I would recommend using Python 3 while following along in these courses.

Ross Thompson
Ross Thompson
7,706 Points

Thanks Ryan, big noob error on my part. I'm using a python 2 interpreter to read python 3 code!

Tate Price
PRO
Tate Price
Pro Student 6,450 Points

can you post exactly what the error message says