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 trialBryan 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,441 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,441 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,173 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!