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 (Retired) Shopping List Shopping List Project

Trent Burkenpas
Trent Burkenpas
22,388 Points

Have some issues printing my shopping_list. After I type in DONE my list does not want to show up!

Here is my code

shopping_list = []

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

while True:
  new_item = input("> ")

  if new_item == 'DONE':
    break

    shopping_list.append(new_item)
    print("Added: List has {} items.".format(len(shopping_list)))
    continue

print("Here's your list:")

for item in shopping_list:
  print(item)

Thank You

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

You have a break that's followed by equally-indented lines. Those lines will never be run because they belong to the block that the break is in and the break kicks everything back out to the code after the while loop.

Kenneth Love Your point is right. But, he mentioned he has only issues with printing shopping list. That does mean Issue should be after while termination.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Karthikeyan Palaniswamy His break comes before anything gets added to the list, which would result in a blank list being printed, which would be why the list doesn't show up.

1 Answer

Your program works great. I do not find any mistakes in there. I would recommend you to check indentation properly. In Python Indentation does matter a lot. You may know Python is a indentation language.

Please use the code below. I did intend them well in my text editor.

shopping_list = []
print("What should we pick up at the store?")
print("Enter 'DONE' to stop adding items")
while True:
  new_item = raw_input("> ")
  if new_item == 'DONE':
    break
  shopping_list.append(new_item)
  print("Added: List has {} items.".format(len(shopping_list)))
  continue
print("Here's your list:")
for item in shopping_list:
  print(item)

I hope It helps

Trent Burkenpas
Trent Burkenpas
22,388 Points

oh I see. The indentation issue. Thanks!