-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder.py
More file actions
24 lines (20 loc) · 775 Bytes
/
order.py
File metadata and controls
24 lines (20 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Order:
def __init__(self, customer):
self.customer = customer
self.cart = []
def add_to_cart(self, item):
self.cart.append(item)
def view_cart(self):
print(f"\n{self.customer}'s cart:")
for item in self.cart:
print(f"- {item.get_name()}: ${item.get_price():.2f}")
def generate_bill(self):
total_price = sum([item.get_price() for item in self.cart])
print(f"\n{'*' * 30}")
print(f"\n{self.customer}'s bill:\n")
print(f"{'Item':<10} {'Price':>10}")
print(f"{'-' * 20}")
for item in self.cart:
print(f"{item.get_name():<10} ${item.get_price():>10.2f}")
print(f"\n{'Total':<10} ${total_price:>10.2f}")
print(f"\n{'*' * 30}")