-
Notifications
You must be signed in to change notification settings - Fork 1
/
25-restaurant-menu.py
122 lines (79 loc) · 3.41 KB
/
25-restaurant-menu.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from enum import Enum
class DishType(Enum):
starter = 1
dish = 2
deseert = 3
class Dish:
def __init__(self, name, preparation_time, dish_type: DishType):
self.name = name
self.preparation_time = preparation_time
self.dish_type = dish_type
def __gt__(self, other):
if self.preparation_time > other.preparation_time:
return True
else:
return False
def __lt__(self, other):
if self.preparation_time < other.preparation_time:
return True
else:
return False
def __eq__(self, other):
if self.preparation_time == other.preparation_time:
return True
else:
return False
def __ge__(self, other):
if self.preparation_time >= other.preparation_time:
return True
else:
return False
def __le__(self, other):
if self.preparation_time <= other.preparation_time:
return True
else:
return False
class Menu:
def __init__(self, name):
self.name = name
self.dishes = []
def add_dish(self, dish: Dish):
self.dishes.append(dish)
def get_starters(self):
return [dish for dish in self.dishes if dish.dish_type == "starter"]
def get_dishes(self):
return [dish for dish in self.dishes if dish.dish_type == "dish"]
def get_desserts(self):
return [dish for dish in self.dishes if dish.dish_type == "dessert"]
def get_minimum_preparation_time(self):
starter_time = min([dish.preparation_time for dish in self.get_starters()]) if len(self.get_starters()) > 0 else 0
dish_time = min([dish.preparation_time for dish in self.get_dishes()]) if len(self.get_dishes()) > 0 else 0
dessert_time = min([dish.preparation_time for dish in self.get_desserts()]) if len(self.get_desserts()) > 0 else 0
return starter_time + dish_time + dessert_time
def get_maximum_preparation_time(self):
starter_time = max([dish.preparation_time for dish in self.get_starters()]) if len(self.get_starters()) > 0 else 0
dish_time = max([dish.preparation_time for dish in self.get_dishes()]) if len(self.get_dishes()) > 0 else 0
dessert_time = max([dish.preparation_time for dish in self.get_desserts()]) if len(self.get_desserts()) > 0 else 0
return starter_time + dish_time + dessert_time
def __add__(self, other):
new_menu = Menu(self.name + ' & ' + other.name)
for dish in self.dishes + other.dishes:
new_menu.add_dish(dish)
return new_menu
def __str__(self):
text = ""
if len(self.get_starters()) > 0:
text = text + "STARTER\n"
for dish in sorted(self.get_starters(), key=lambda x: x.preparation_time):
text = text + dish.name + '\n'
text = text + "\n"
if len(self.get_dishes()) > 0:
text = text + "DISH\n"
for dish in sorted(self.get_dishes(), key=lambda x: x.preparation_time):
text = text + dish.name + '\n'
text = text + "\n"
if len(self.get_desserts()) > 0:
text = text + "DESSERT\n"
for dish in sorted(self.get_desserts(), key=lambda x: x.preparation_time):
text = text + dish.name + '\n'
return text