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 trialRodrigo Muñoz
Courses Plus Student 20,171 Pointsshopping_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":
break
shopping_list.append(new_item)
print("Added! List has {} items".format(len(shopping_list)))
continue
print("Here is your list:")
for item in shopping_list:
print(item)
1 Answer
shezazr
8,275 Pointsok 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: ")
Rodrigo Muñoz
Courses Plus Student 20,171 PointsRodrigo Muñoz
Courses Plus Student 20,171 PointsThank you very much! I will have this always in mind.