-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (32 loc) · 1.19 KB
/
main.py
File metadata and controls
43 lines (32 loc) · 1.19 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
class Product:
def __init__(self, name: str, price: float) -> None:
self.name = name
self.price = price
def total_price_for_product(self, quantity):
return round(self.price * quantity, 2)
class ShoppingCart:
def __init__(self) -> None:
self.products = []
self.quantities = []
def add_product_to_cart(self, product: Product, quantity):
self.products.append(product)
self.quantities.append(quantity)
def total_price_for_all(self):
total = 0
for (product, quantity) in zip(self.products, self.quantities):
total += product.total_price_for_product(quantity)
return round(total, 2)
product1 = Product("beer", 38)
product2 = Product("milk", 44.5)
product3 = Product('bar', 19.99)
product4 = Product('sausage', 30)
product5 = Product('pasta', 36)
product6 = Product('tomato', 7.7)
cart = ShoppingCart()
cart.add_product_to_cart(product1, 8)
cart.add_product_to_cart(product2, 1)
cart.add_product_to_cart(product3, 2)
cart.add_product_to_cart(product4, 0)
cart.add_product_to_cart(product5, 3)
cart.add_product_to_cart(product6, 7)
print(f'Total price for all products = {cart.total_price_for_all()} UAH')