-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path007-shopping_list.py
More file actions
executable file
·54 lines (42 loc) · 1.39 KB
/
Copy path007-shopping_list.py
File metadata and controls
executable file
·54 lines (42 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
#Shopping list
#Step 1: Initialize an empty shopping list
shopping_list = []
#Step 2: To define the main menu
def show_menu():
print("\n---Shopping List Menu---")
print("1. View the shopping list")
print("2. Add and item")
print("3. Remove an item")
print("4. Clear List")
print("5. Exit")
#Step 3: Main program loop
while True:
show_menu()
choice = input("Enter your choice (1-5): ")
if choice == "1":
print("\n---Shopping list---")
if not shopping_list:
print("Your shopping list is empty")
else:
for index,item in enumerate(shopping_list):
print(f'{index+1}. {item}')
elif choice == "2":
item = input("Enter the item to add: ")
shopping_list.append(item)
print(f'{item} has been added to the shopping list.')
elif choice == "3":
item = input("Enter the item to remove: ")
if item in shopping_list:
shopping_list.remove(item)
print(f'{item} has been removed from the shopping list.')
else:
print(f'{item} is not in the shopping list.')
elif choice == "4":
shopping_list.clear()
print("The shopping list has been cleared.")
elif choice == "5":
print("Goodbye! Happy Shopping!")
break
else:
print("Invalid choice. Please try again.")