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
Juan Perez
Courses Plus Student 8,944 PointsI Get an Traceback error
I get a Traceback error. What could be causing this error? This is my code
# make a list that will hold onto our items
shopping_list = []
# print out instructions on how to use the app
print("What should we pick up at the store?")
print("Enter 'DONE' to stop adding items.")
while True:
# ask for new items
new_item = input("> ")
# be able to quit the app
if new_item == "DONE":
break
# add new items to our list
shopping_list.append(new_item)
# print out the list
print("Here is your list:")
for item in shopping_list:
print(item)
What should we pick up at the store? Enter 'DONE' to stop adding items.
apples Traceback (most recent call last): File "shoppinglist.py", line 10, in <module> new_item = input("> ") File "<string>", line 1, in <module> NameError: name 'apples' is not defined
2 Answers
Iain Simmons
Treehouse Moderator 32,305 PointsSo first up, it's not a traceback error, it's a NameError. The traceback is just output from the error so you can 'trace back' to where the error originated.
As for the actual error, this comes from using Python version 2.x instead of 3.x. input in Python 2 treats the response to the prompt to the user as an actual Python expression, instead of a string.
Treehouse courses all use Python 3 syntax, but if you want to use Python 2, use the raw_input function instead of input.
Juan Perez
Courses Plus Student 8,944 PointsThanks Both!