Python Python Basics (2015) Shopping List App Shopping List Introduction

got an indentation error when i run my shopping_list app

# make a list to hold onto our items
shopping_list = []

# print out instructions on how to use the app
print("what should we pick at the store?")
print("Enter 'DONE'to stop adding items.")

while True:
# ask for new items

new_item = input("> ")

# be able to quit the app
if new_item == "DONE":
  break

# add new item to our list

shopping_list.append(new_item)


# print out the list
print("Here's your list:")

for item in shopping_list:
  print(item)


File "shopping_list.py", line 11                                                                             
    new_item = input("> ")                                                                                     
           ^                                                                                                   
IndentationError: expected an indented block

1 Answer

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 56,301 Points

Hi there,

everything that's inside the while loops needs indenting by 4 spaces.

Any other blocks of code within the loop, such as the if and for need their lines of code indenting by a further four spaces.

I don't know what should be in the loop etc, but this may be better:

# make a list to hold onto our items
shopping_list = []

# print out instructions on how to use the app
print("what should we pick at the store?")
print("Enter 'DONE'to stop adding items.")

while True:
    # ask for new items

    new_item = input("> ")

    # be able to quit the app
    if new_item == "DONE":
        break

    # add new item to our list

    shopping_list.append(new_item)


    # print out the list
    print("Here's your list:")

    for item in shopping_list:
        print(item)

I hope that helps.

Steve.