Task: Create a python program that behaves like a shopping list. It should include the…
- User
Task: Create a python program that behaves like a shopping list. It should include the following functionality.
Reference code from the previous lesson for help.
Greet the user Give the user the option to view the list Give the user the option to add an item to the list Give the user the option to remove a specific item from the list Give the user the option to remove the last item from the list use this as a start# Shopping List Program
Initialize an empty list called shopping_list
#add a weclome message
while True: # Ask the user for an item to add to the shopping list #reponse =
#conditional if statements to take action based on user response - Assistant
Here's a simple Python program that acts as a shopping list. It includes the functionalities you requested, such as greeting the user, allowing them to view the list, add items, and remove specific or the last item from the list:
- User
make it without using #
- Assistant
Sure! Here’s the shopping list program without comments (the
#symbols):shopping_list = [] print("Welcome to the Shopping List Program!") while True: print("\nOptions:") print("1. View shopping list") print("2. Add item to shopping list") print("3. Remove specific item from shopping list") print("4. Remove the last item from shopping list") print("5. Exit") choice = input("Please enter your choice (1-5): ") if choice == "1": if shopping_list: print("\nYour Shopping List:") for item in shopping_list: print(f"- {item}") else: print("\nYour shopping list is currently empty.") elif choice == "2": item_to_add = input("Enter the item you want to add: ") shopping_list.append(item_to_add) print(f"{item_to_add} has been added to your shopping list.") elif choice == "3": item_to_remove = input("Enter the item you want to remove: ") if item_to_remove in shopping_list: shopping_list.remove(item_to_remove) print(f"{item_to_remove} has been removed from your shopping list.") else: print(f"{item_to_remove} is not in your shopping list.") elif choice == "4": if shopping_list: removed_item = shopping_list.pop() print(f"{removed_item} has been removed from your shopping list.") else: print("Your shopping list is already empty.") elif choice == "5": print("Thank you for using the Shopping List Program. Goodbye!") break else: print("Invalid choice. Please enter a number between 1 and 5.")