-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask32.py
93 lines (73 loc) · 2.89 KB
/
task32.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
class Initialization:
def __init__(self, capacity, food):
if not isinstance(capacity, int):
print("Кількість людей має бути ціле число")
else:
self.capacity = capacity
self.food = food
class Vegetarian(Initialization):
def __init__(self, capacity, food):
super().__init__(capacity, food)
def __str__(self):
return f'{self.capacity} людей вибирають не Їсти мясо. Вони віддають перевагу {self.food}'
class MeatEater(Initialization):
def __init__(self, capacity, food):
super().__init__(capacity, food)
def __str__(self):
return f'{self.capacity} людей їсть мясо. Окрім мяса вони також їдять {self.food}'
class SweetTooth(Initialization):
def __init__(self, capacity, food):
super().__init__(capacity, food)
def __str__(self):
return f'Любителів солодкого є {self.capacity}. Окрім солодкого вони надають перевагу {self.food}'
def __eq__(self, other):
if isinstance(other, int):
if other == self.capacity:
return True
else:
return False
elif isinstance(other, (Vegetarian, MeatEater)):
if other.capacity == self.capacity:
return True
else:
return False
else:
return f'Неможливо порівняти солодкоїжок з {other}'
def __lt__(self, other):
if isinstance(other, int):
if self.capacity < other:
return True
else:
return False
elif isinstance(other, (Vegetarian, MeatEater)):
if self.capacity < other.capacity:
return True
else:
return False
else:
return f'Неможливо порівняти солодкоїжок з {other}'
def __gt__(self, other):
if isinstance(other, int):
if self.capacity > other:
return True
else:
return False
elif isinstance(other, (Vegetarian, MeatEater)):
if self.capacity > other.capacity:
return True
else:
return False
else:
return f'Неможливо порівняти солодкоїжок з {other}'
v_first = Vegetarian(10000, ['горіхи', 'овочі', 'фрукти'])
print(v_first)
v_second = Vegetarian([23], ['nothing'])
m_first = MeatEater(15000, ['смажена кртoпля', 'риба'])
print(m_first)
s_first = SweetTooth(30000, ['морозиво', 'шоколад', 'чіпси'])
print(s_first)
print(s_first > v_first)
print(30000 == s_first)
print(s_first == 25000)
print(100000 < s_first)
print(100 < s_first)