-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshopping.py
More file actions
77 lines (64 loc) · 2.39 KB
/
Copy pathshopping.py
File metadata and controls
77 lines (64 loc) · 2.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def display_items(items):
print("Available items:")
for item, price in items.items():
print(f"Name: {item} Price: {price}")
def print_cart(cart):
print("Current Cart:")
for item, (quantity, price) in cart.items():
total = quantity * price
print(f"{item}, Quantity: {quantity}, Price: {price}, Total: {total}")
print()
def main():
items = {
'Bread': 40,
'Cookies': 80,
'Butter': 120,
'Cheese': 180,
'Yoghurt': 60
}
cart = {}
while True:
print("\nWhat do you want to do?")
print("Enter 1 for viewing the items")
print("Enter 2 for adding the items in cart")
print("Enter 3 for updating the items in cart")
print("Enter 4 for deleting the items in cart")
print("Enter 5 for printing bill")
print("Enter 6 to exit")
choice = int(input("Enter your choice: "))
if choice == 1:
display_items(items)
elif choice == 2:
item_name = input("Enter the item name: ").capitalize()
if item_name in items:
quantity = int(input("Enter the quantity: "))
if item_name in cart:
cart[item_name][0] += quantity
else:
cart[item_name] = [quantity, items[item_name]]
else:
print("Item not available.")
elif choice == 3:
item_name = input("Which item to be updated: ").capitalize()
if item_name in cart:
quantity = int(input("Enter the quantity to be updated: "))
cart[item_name][0] = quantity
else:
print("Item not in cart.")
elif choice == 4:
item_name = input("Which item to be removed: ").capitalize()
if item_name in cart:
del cart[item_name]
else:
print("Item not in cart.")
elif choice == 5:
print_cart(cart)
total_amount = sum(quantity * price for quantity, price in cart.values())
print(f"Total Amount of Bill: {total_amount}")
elif choice == 6:
print("Exiting... Thank you for shopping!")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()