-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grocery.py
50 lines (43 loc) · 1.45 KB
/
Grocery.py
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
# Grocery List Application
# Initialize an empty list to store grocery items
grocery_list = []
# Function to add an item to the grocery list
def add_item(item):
grocery_list.append(item)
print(f"Added '{item}' to your grocery list.")
# Function to view the grocery list
def view_list():
if not grocery_list:
print("Your grocery list is empty.")
else:
print("Grocery List:")
for i, item in enumerate(grocery_list, 1):
print(f"{i}. {item}")
# Function to remove an item from the grocery list
def remove_item(item_index):
if 1 <= item_index <= len(grocery_list):
removed_item = grocery_list.pop(item_index - 1)
print(f"Removed '{removed_item}' from your grocery list.")
else:
print("Invalid item index!")
# Main program loop
while True:
print("\nGrocery List Application")
print("1. Add Item")
print("2. View Grocery List")
print("3. Remove Item")
print("4. Quit")
choice = input("\n Enter your choice: ")
if choice == "1":
item = input("Enter the item to add to your grocery list: ")
add_item(item)
elif choice == "2":
view_list()
elif choice == "3":
item_index = int(input("Enter the item number to remove from your grocery list: "))
remove_item(item_index)
elif choice == "4":
print("Good Bye.\n Created By Qavi Shaikh")
break
else:
print("Invalid choice. Please select a valid option.")