-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShopping_cart.py
More file actions
46 lines (39 loc) · 1.24 KB
/
Shopping_cart.py
File metadata and controls
46 lines (39 loc) · 1.24 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
# This is sets practical
# This is example of shopping cart for example you can not add Duplicate Item in the cart
shopping_cart = set()
def add_item(item):
shopping_cart.add(item)
print(f"Added {item} to your cart.")
def remove_item(item):
if item in shopping_cart:
shopping_cart.remove(item)
print(f"Removed {item} from your cart.")
else:
print(f"{item} is not in your cart.")
def display_cart():
if not shopping_cart:
print("Your cart is empty.")
else:
print("Items in your cart:")
for item in shopping_cart:
print(item)
while True:
print("\nOptions:")
print("1. Add item to cart")
print("2. Remove item from cart")
print("3. Display cart")
print("4. Quit"+"\n")
choice = input("Enter Number What you want to do: ")
if choice == '1':
item = input("Enter the item to add: "+"\n")
add_item(item)
elif choice == '2':
item = input("Enter the item to remove: "+"\n")
remove_item(item)
elif choice == '3':
display_cart()
elif choice == '4':
print("Thank you for shopping with us!","\n Created by Qavi Shaikh")
break
else:
print("Invalid choice. Please select a valid option.")