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

Python Python Basics (2015) Shopping List App Shopping List Introduction

Jonathan Whelchel
Jonathan Whelchel
2,096 Points

List isn't working

shopping_list = []
print("What do you want to do today?")
print("To quit type in DONE")

while True:
  new_item = input("> ")
  if new_item == "DONE":
      break
  shopping_list.append(new_item)
print("Here's your list")
for item in shopping_list:
    print(item)

above is my code. DONE will break the loop, but at the end what is printed is the word DONE. Can someone please help

It is difficult to find the problem without seeing the exact layout of your code as it appears in your editor because indentation is vital in python.

I tried typing in your program and it worked fine for me but I know that I used correct indentation. I suspect that there may be a problem with your indentation.

You can display code exactly if you use markdown in your post. To display Python code, you need to do the following:

Type three backticks (that is the key to the left of the key with 1 and above the tab key), then type the word python. Hit enter and type your code in EXACTLY as it appears in your program. When you are finished with your code, on a new line type in three backticks.

1 Answer

Hi Jonathan

Check you indentation. I amended your code slightly and it seems to work. See below

shopping_list = []
print("What do you want to do today?")
print("To quit type in DONE")

while True:
  new_item = input("> ")
  if new_item == "DONE":
      break
  shopping_list.append(new_item)
  print("Here's your list")
  for item in shopping_list:
      print(item)
Jonathan Whelchel
Jonathan Whelchel
2,096 Points

ok this helps a ton! random question. When I paste this code into terminal, it doesn't work. it does the first two print functions but when trying to add items to the list it doesn't work. Why does it work in workspaces here but not terminal?