Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions 01/task_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Product:
"""Describing product"""

def __init__(self, name: str, price: float):
self.name = name
self.price = price

def get_total(self, count: float):
"""Calculating total price for the product"""
return round(self.price * count, 2)


class ShoppingCart:
"""Describing the shopping cart"""

def __init__(self):
self.total_cart = []

def add(self, product: Product, count: float = 1):
"""Adding products to the cart"""

total_product_price = product.get_total(count)
self.total_cart.append(total_product_price)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

За такої реалізації легше було зробити одне поле, куди складати суму покупки.
Але таким чином проігноровано умову, зберігати кільсть товару у кошику.
Це треба доробити.


def total_cart_sum(self):
"""Calculating the total cart sum"""

return sum(self.total_cart)


prod1 = Product('lemon', 15.10)
print(prod1.get_total(0.7))
prod2 = Product('strawberry', 150)
prod3 = Product('cucumber', 100)
cart1 = ShoppingCart()
cart1.add(prod1, 0.7)
cart1.add(prod2, 20)
cart1.add(prod3, 20)
cart1.add(prod1, 5)
print(cart1.total_cart_sum())
print(cart1.total_cart)