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

What is wrong here?

shopping_list = list()

print("What would you like from the store? ")
print("Enter 'DONE' to stop adding things. ")

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 is your list: ")


for item in shopping_list:
    print(item)

When ever I run the script it doesn't say Added! List has _ items in it after adding a item, or it doesn't say what I have in the list after.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,989 Points

A few things to correct:

shopping_list = list()

print("What would you like from the store? ")
print("Enter 'DONE' to stop adding things. ")

while True:
    new_item = input("> ")

    if new_item == 'DONE':
        break

    # This section outdented (was aligned to breack statement above)
    shopping_list.append(new_item) #<-- Changed to new_item from new.item
    print("Added! List has {} items.".format(len(shopping_list)))
    # continue # <-- continue not needed as last command in while block

print("Here is your list: ")

for item in shopping_list:
    print(item)