-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoffee.py
More file actions
82 lines (60 loc) · 1.9 KB
/
coffee.py
File metadata and controls
82 lines (60 loc) · 1.9 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
78
79
80
81
82
class Coffee:
def __init__(self, name, price):
self.name = name
self.price = price
class Order:
def __init__(self):
self.items = []
def add_item(self, coffee):
self.items.append(coffee)
print(f"Added {coffee.name} to your order.")
def total(self):
return sum(item.price for item in self.items)
def show_order(self):
if not self.items:
print("No items in order.")
return
print("\nYour Order:")
for i, item in enumerate(self.items, 1):
print(f"{i}. {item.name} - ${item.price}")
print(f"Total: ${self.total()}\n")
def checkout(self):
if not self.items:
print("Your cart is empty.")
return
self.show_order()
confirm = input("Proceed to checkout? (yes/no): ").strip().lower()
if confirm == 'yes':
print("Order confirmed! Thank you.")
self.items.clear()
else:
print("Checkout cancelled.")
def main():
menu = [
Coffee("Espresso", 2.5),
Coffee("Latte", 3.5),
Coffee("Cappuccino", 3.0),
Coffee("Americano", 2.0)
]
order = Order()
while True:
print("\n--- Coffee Menu ---")
for i, coffee in enumerate(menu, 1):
print(f"{i}. {coffee.name} - ${coffee.price}")
print("5. View Order")
print("6. Checkout")
print("7. Exit")
choice = input("Choose an option: ")
if choice in ['1', '2', '3', '4']:
order.add_item(menu[int(choice) - 1])
elif choice == '5':
order.show_order()
elif choice == '6':
order.checkout()
elif choice == '7':
print("Thanks for visiting. Goodbye!")
break
else:
print("Invalid choice. Try again.")
if __name__ == "__main__":
main()