-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_5_3.py
More file actions
78 lines (58 loc) · 2.34 KB
/
module_5_3.py
File metadata and controls
78 lines (58 loc) · 2.34 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
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
class House:
def __init__(self, name, number_of_floors):
self.name = name
self.number_of_floors = number_of_floors
def go_to(self, new_floor):
self.new_floor = new_floor
if self.new_floor in range(1, self.number_of_floors + 1):
for i in range(1, self.new_floor + 1):
print(i)
else:
print('Такого этажа не существует')
def __len__(self):
return self.number_of_floors
def __str__(self):
return f'Название: {self.name}, кол-во этажей: {self.number_of_floors}'
def __eq__(self, other):
if isinstance(other, House) and isinstance(other.number_of_floors, int):
return self.number_of_floors == other.number_of_floors
def __lt__(self, other):
if isinstance(other, House) and isinstance(other.number_of_floors, int):
return self.number_of_floors < other.number_of_floors
def __le__(self, other):
if isinstance(other, House) and isinstance(other.number_of_floors, int):
return self.number_of_floors <= other.number_of_floors
def __gt__(self, other):
if isinstance(other, House) and isinstance(other.number_of_floors, int):
return self.number_of_floors > other.number_of_floors
def __ge__(self, other):
if isinstance(other, House) and isinstance(other.number_of_floors, int):
return self.number_of_floors >= other.number_of_floors
def __ne__(self, other):
if isinstance(other, House) and isinstance(other.number_of_floors, int):
return self.number_of_floors != other.number_of_floors
def __add__(self, value):
if isinstance(value, int):
self.number_of_floors += value
return self
def __radd__(self, value):
return self.__add__(value)
def __iadd__(self, value):
return self.__add__(value)
h1 = House('ЖК Эльбрус', 10)
h2 = House('ЖК Акация', 20)
print(h1)
print(h2)
print(h1 == h2) # __eq__
h1 = h1 + 10 # __add__
print(h1)
print(h1 == h2)
h1 += 10 # __iadd__
print(h1)
h2 = 10 + h2 # __radd__
print(h2)
print(h1 > h2) # __gt__
print(h1 >= h2) # __ge__
print(h1 < h2) # __lt__
print(h1 <= h2) # __le__
print(h1 != h2) # __ne__