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

shopping_list app

shopping_items = []

print("Please enter the items to be added") print("Enter 'DONE' to stop adding the items")

while 1<2: items = input("-")

if items == 'DONE':
    break
shopping_items.append(items)

print("Here is your list:")

for item in items: print(items)

what is wrong with this code

2 Answers

shopping_items = []


print("Please enter the items to be added") 
print("Enter 'DONE' to stop adding the items")

while True: 

  items = input("-")

  if items.upper() == 'DONE':
    break
  shopping_items.append(items)


print("Here is your list:")

for item in shopping_items: 
  print(item)

For the most part it seemed to be indentation problems to get it working. You also needed to reference your list in your for loop and not items. items was being appended to the shopping list everythim the loop ran and being assigned new information when the loop started again. I'm not sure what the also changed the while 1<2: to while True:

also added upper() in the if statement so that it does not matter how the user typed 'DONE' it would exit the loop

It does not have syntax error.While executing the program is not taking the second input.

the if statement works fine, it seems the only issue was in your for loop to print the list. it was referencing items which was not where you had stored your list. you had to loop through the shopping_items list.