Skip to content
Snippets Groups Projects
Commit 6e47da0c authored by Санников Тимофей's avatar Санников Тимофей
Browse files

added classwork

parent 398f7d36
No related branches found
No related tags found
No related merge requests found
class Rectangle:
rectcnt = 0
def __init__(self, x1, y1, x2, y2):
self.x1, self.x2, self.y1, self.y2 = x1, x2, y1, y2
self.__class__.rectcnt += 1
k = int(Rectangle.rectcnt)
setattr(self, f'rect_{k}', k)
def __str__(self):
return f'{self.__class__.rectcnt}:({self.x1}, {self.y1})({self.x1}, {self.y2})({self.x2}, {self.y1})({self.x2}, {self.y2})'
def __lt__(self, item):
return abs(self) < abs(item)
def __eq__(self, item):
return abs(self) == abs(item)
def __abs__(self):
return (self.x2-self.x1)*(self.y2-self.y1)
def __mul__(self, item):
return Rectangle(self.x1*item, self.y1*item, self.x2*item, self.y2*item)
def __rmul__(self, item):
return Rectangle(self.x1*item, self.y1*item, self.x2*item, self.y2*item)
def __getitem__(self, item):
if item == 0:
return f'({self.x1}, {self.y1})'
if item == 1:
return f'({self.x1}, {self.y2})'
if item == 2:
return f'({self.x2}, {self.y1})'
if item == 3:
return f'({self.x2}, {self.y2})'
a,b = Rectangle(0,0,4,4,), Rectangle(1,2,3,4)
print(a, b)
print(a.rectcnt, a.rect_1)
print(abs(a),abs(b))
print(b < a, a == b)
print(b*5, a*2)
print(a[1])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment