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 (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

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.