Python Introducing Lists Build an Application Add Items

greg solt
greg solt
510 Points

Question about Program - Don't get the number of items to show

Hello. The script runs, but does not return the number of items.

greg solt
greg solt
510 Points
# Create a new empty list called shopping_list
shopping_list = []

# Create a function named add_to_list that delcares a parameter named item
  # Add the item to the list
def add_to_list(item):
    shopping_list.append(item)
    # Notify user that the item has been added, and state the number of items in the list currently
    print("Added:list has {} items".format(len(shopping_list)))


def show_help():
  print("What should we pick up at the store?")
  print("""
Enter 'DONE' to stop adding items
Enter 'HELP' for this Help
  """)

show_help()

while True:
  new_item = input(">")

  if new_item == 'DONE':
    break
  elif new_item == 'HELP':
    show_help()
    continue

    # Call add_to_list with new_item
    add_to_list(new_item)

[MOD: added ```python formatting -cf]

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 56,829 Points

The add_to_list(new_item) is inside the elif block, and after the continue statement. Hence, it will never be reached. Unindent the line and it should work.

Post back if you need more help. Good Luck!

greg solt
greg solt
510 Points

Thank you very much.

I am having this same issue. I unindented the call as suggested and that did not resolve the problem.

Chris Freeman
Chris Freeman
Treehouse Moderator 56,829 Points

I suggest posting your code in a new forum question. Feel free to tag me in the post.

jassem aldhaheri
jassem aldhaheri
11,031 Points

unindent just after the while statement.