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

Andreas cormack
Andreas cormack
Python Web Development Techdegree Graduate 29,840 Points

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?