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


Rex Orioko
Rex Orioko
3,234 Points

Please tell me whats wrong with this python code

make a list

shopping_list = []

print instructions how to use app

print("what should we pick up at store") print("Enter 'DONE' to stop adding items")

while True: # ask for new items new_item = input("> ")

# quit app
if new_item == "DONE":

# add new items to list

print out app

print("Here's your list:")

for item in shopping_list: print(item)

Rex Orioko
Rex Orioko
3,234 Points

I keep getting this when i run code: Traceback (most recent call last): File "/Users/rexorioko/Desktop/functions.py", line 12, in <module> new_item = input("> ") File "<string>", line 1, in <module> NameError: name 'bread' is not defined

Stuart Wright
Stuart Wright
41,118 Points

Can you post your entire script inside the code markup tags please? It's difficult to tell what's happening with the current formatting, and it makes it impossible tell if the indentation is all correct.

i dont know if i am wrong, but did you gave input as 'bread' or just bread.

Not sure but could you please try both, as i can't see any problem in the code.

2 Answers

Steven Parker
Steven Parker
229,920 Points

This code seems to work.

But I had to make many assumptions about indentation, and I don't know if it was intended to accomplish any particular goal (such as in a code challenge). If the latter, please post a link the course page you were working with.

And always when posting code, usethe instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:

Rex Orioko
Rex Orioko
3,234 Points

I was running on my local machine and was defaulted to python 2.7, i ha to change input to raw_input