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 Second Shopping List App

Here's how I've coded this app. Any tips on how to improve it?

# Create list
shopping_list = []

# Show help
def show_help():
    print("Here's what you can do:")
    print("- Type SHOW to see your current list.")
    print("- Type ADD to see your current list.")
    print("- Type REMOVE to remove an item from your list.")
    print("- Type STOP to quit the app.")
    print("- Type HELP to see these instructions again.")
    print("=" * 30)

# Add new item
def add_new():
    print("Tip: You can add more than one item by separating them with commas.")
    item = input("Describe the new item: ")
    if len(item.split(",")) == 1:
        shopping_list.append(item)
        print("New item added!")
    else:
        shopping_list.extend(item.split(','))
        print("New items added!")

# Remove item
def remove_item():
    if len(shopping_list) == 0:
        print("Your list is empty!")
        return False
    item = input("Tell me which item you'd like to remove: ")
    try:
        shopping_list.remove(item)
    except ValueError:
        print("This item is not on your list!")
    else:
        print("Item removed!")

# Show list
def show_list():
    if len(shopping_list) != 0:
        for index, item in enumerate(shopping_list):
            print("{}. {}".format((index + 1), item))
    else:
        print("Your list is empty!")

show_help()

# Loop
while True:
    action = input("> ").upper()
    if action == "SHOW":
        show_list()
        print("=" * 30)
        continue
    elif action == "ADD":
        add_new()
        print("=" * 30)
        continue
    elif action == "REMOVE":
        remove_item()
        print("=" * 30)
        continue
    elif action == "HELP":
        show_help()
        continue
    elif action == "DONE":
        print("Bye!")
        break
    else:
        print("That's not a valid action!")
        print("=" * 30)
        continue