-
Notifications
You must be signed in to change notification settings - Fork 445
/
burger.py
48 lines (33 loc) · 1.46 KB
/
burger.py
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
from typing import List
from praktikum.bun import Bun
from praktikum.ingredient import Ingredient
class Burger:
"""
Модель бургера.
Бургер состоит из булочек и ингредиентов (начинка или соус).
Ингредиенты можно перемещать и удалять.
Можно распечать чек с информацией о бургере.
"""
def __init__(self):
self.bun = None
self.ingredients: List[Ingredient] = []
def set_buns(self, bun: Bun):
self.bun = bun
def add_ingredient(self, ingredient: Ingredient):
self.ingredients.append(ingredient)
def remove_ingredient(self, index: int):
del self.ingredients[index]
def move_ingredient(self, index: int, new_index: int):
self.ingredients.insert(new_index, self.ingredients.pop(index))
def get_price(self) -> float:
price = self.bun.get_price() * 2
for ingredient in self.ingredients:
price += ingredient.get_price()
return price
def get_receipt(self) -> str:
receipt: List[str] = [f'(==== {self.bun.get_name()} ====)']
for ingredient in self.ingredients:
receipt.append(f'= {str(ingredient.get_type()).lower()} {ingredient.get_name()} =')
receipt.append(f'(==== {self.bun.get_name()} ====)\n')
receipt.append(f'Price: {self.get_price()}')
return '\n'.join(receipt)