Advertisement
AtEchoOff

Python Shopping List Exercise

Feb 7th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. # Step 1: Create an empty list
  2. shopping_list = []
  3.  
  4. # Step 2: Get 5 items from the user
  5. for i in range(5):
  6. item = input("Enter an item to add to your shopping list: ")
  7. shopping_list.append(item)
  8.  
  9. # Step 3: Print the shopping list
  10. print("\nYour shopping list:", shopping_list)
  11.  
  12. # Step 4: Ask for an item to remove
  13. remove_item = input("\nWhich item would you like to remove? ")
  14.  
  15. # Step 5: Remove the item if it exists
  16. if remove_item in shopping_list:
  17. shopping_list.remove(remove_item)
  18. else:
  19. print(f"{remove_item} was not found in your shopping list.")
  20.  
  21. # Step 6: Print the updated list
  22. print("\nUpdated shopping list:", shopping_list)
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement