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.

Bryan Lane
371 PointsNameError: shopping_list is not defined
Hi! I'm trying to run this in my workspace and am getting a NameError in line one:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'shopping_list' is not defined
Here is my code:
shopping_list = 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('Added! List has {} items.".format(len(shopping_list)))
continue
print('Here's your list:')
for items in shopping_list print(items)
Any ideas?

Bryan Lane
371 PointsNot sure why it posted like that:
[shopping_list = 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('Added! List has {} items.".format(len(shopping_list))) continue
print('Here's your list:')
for items in shopping_lis print(items)]

Chris Freeman
Treehouse Moderator 68,166 PointsAdd triple-backtick before and after your code block. Add the word python immedate after the opening triple backtick to get python coloring.
2 Answers

Chris Freeman
Treehouse Moderator 68,166 PointsHere's your code formated below, with a few corrections:
shopping_list = 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': #<-- missing colon
break
shopping_list.append(new_item)
print('Added! List has {} items.'.format(len(shopping_list))) #<--mismatched quote marks
continue
print("Here's your list:") #<-- fixed conflicting single quotes
for items in shopping_list: #<-- corrected misspelled "shoppinglis"; add missing colon
print(items)
Seems to run well now.

Bryan Lane
371 PointsThanks. Seems to work for me now. Much appreciated.

michaelangelo owildeberry
18,172 PointsDid it work?
=)
Trevor Currie
9,289 PointsTrevor Currie
9,289 PointsIf you format your code in a readable way, it'll make it easier to get your question answered!