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!

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

Sebastian Giliberto
Sebastian Giliberto
1,809 Points

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 68,404 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)