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 Introducing Lists Build an Application Add Items

Having issues adding more than one item to the list and having problems exiting application by typing DONE.

# Create a list 
shopping_list = []

# Create a function that adds an item to the list.
def add_list(item):
    shopping_list.append(item)
#Let user know the item has been added and state the number of items in the list.
    print("Added: Item has just been added {}".format(len(shopping_list)))

def show_help():
    print("What should we pickup at the store??")
    print("""
        Enter 'DONE' when you are finished.
        Enter 'HELP' when you need help
        """)
show_help()

while True:
  new_item = input("> ")
    
    
  if new_item == 'DONE':
      break
  elif new_item == 'HELP':
      show_help()
  continue
    
#Call function that adds item to the list
add_list(new_item)

formatted by staff

1 Answer

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi! You need to move the add_list() call inside of your while loop

while True:
  new_item = input("> ")
  if new_item == 'DONE':
      break
  elif new_item == 'HELP':
      show_help()
      # you don't need this its a loop so it will continue anyways-> continue
  else:
    #Call function that adds item to the list
    add_list(new_item)

Ahh. Thanks. Very helpful!