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.

Python

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":
    break

# add new items to list
shopping_list.append(new_item)

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,103 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
221,309 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