-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
75 lines (56 loc) · 1.59 KB
/
main.py
File metadata and controls
75 lines (56 loc) · 1.59 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
from math import sqrt
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def set_width(self, new_width):
self.width = new_width
def set_height(self, new_height):
self.height = new_height
def get_area(self):
return self.width * self.height
def get_perimeter(self):
return 2 * (self.width + self.height)
def get_diagonal(self):
return sqrt(self.width**2 + self.height**2)
def get_picture(self):
if self.height > 50 or self.width > 50:
return 'Too big for picture.'
return f'{"*" * self.width}\n' * self.height
def get_amount_inside(self, shape):
column = round(self.width / shape.width)
row = round(self.height / shape.height)
return row * column
def __repr__(self):
return f'Rectangle(width={self.width}, height={self.height})'
class Square(Rectangle):
def __init__(self, side):
super().__init__(side, side)
def set_width(self, new_width):
super().set_width(new_width)
self.height = new_width
def set_height(self, new_height):
super().set_height(new_height)
self.width = new_height
def set_side(self, new_side):
self.set_width(new_side)
def __repr__(self):
return f'Square(side={self.width})'
# =========================
# Example usage
# =========================
# rect = Rectangle(10, 5)
# print(rect.get_area())
# rect.set_height(3)
# print(rect.get_perimeter())
# print(rect)
# print(rect.get_picture())
# sq = Square(9)
# print(sq.get_area())
# sq.set_side(4)
# print(sq.get_diagonal())
# print(sq)
# print(sq.get_picture())
# rect.set_height(8)
# rect.set_width(16)
# print(rect.get_amount_inside(sq))