Build a Simple Grocery List Manager
Create a Python program that allows users to add items to a grocery list, remove items, and display the current list. This mini-project helps beginners practice working with lists, loops, and functions.
Challenge prompt
Write a Python function called manage_grocery_list() that continuously prompts the user to perform one of the following actions: add an item, remove an item, or display the current grocery list. The function should keep running until the user types 'quit'. When adding, the user inputs the item name to add. When removing, the user inputs the item name to remove if it exists in the list. When displaying, the program prints all items in the grocery list in a clean format.
Guidance
- • Use a while loop to keep the program running until the user types 'quit'.
- • Store the grocery items in a list and update it based on user input.
- • Use conditionals to handle different commands: add, remove, display, and quit.
Hints
- • Use the list methods append() to add items and remove() to delete items from the grocery list.
- • Check if the item exists in the list before trying to remove it to avoid errors.
- • You can use input() for user input and print() to show messages or the list contents.
Starter code
def manage_grocery_list():
grocery_list = []
while True:
command = input("Enter a command (add, remove, display, quit): ").lower()
# Your code hereExpected output
Enter a command (add, remove, display, quit): add Enter the item to add: apples 'apples' has been added. Enter a command (add, remove, display, quit): display Your grocery list: - apples Enter a command (add, remove, display, quit): remove Enter the item to remove: apples 'apples' has been removed. Enter a command (add, remove, display, quit): quit Goodbye!
Core concepts
Challenge a Friend
Send this duel to someone else and see if they can solve it.