forked from freeCodeCamp/boilerplate-polygon-area-calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape_calculator.py
62 lines (49 loc) · 1.56 KB
/
shape_calculator.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
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def set_width(self, width):
self.width = width
return self.width
def set_height(self, height):
self.height = height
return self.height
def get_perimeter(self):
perimeter = 2*(self.height + self.width)
return perimeter
def get_area(self):
area = self.height * self.width
return area
def get_diagonal(self):
diagonal = (self.height**2 + self.width**2)**0.5
return diagonal
def get_picture(self):
picture_str = ""
if self.width > 50 or self.height > 50:
return "Too big for picture."
for i in range(self.height):
picture_str += "*" * self.width+"\n"
return picture_str
def get_amount_inside(self, shape):
return (self.width // shape.width) * (self.height // shape.height)
def __str__(self):
return f"Rectangle(width={self.width}, height={self.height})"
class Square(Rectangle):
def __init__(self, side):
self.width = side
self.height = side
def set_side(self, side):
self.side = side
self.width = side
self.height = side
return self.side
def set_width(self, width):
self.width = width
self.height = width
return self.width
def set_height(self, height):
self.width = height
self.height = height
return self.height
def __str__(self):
return f"Square(side={self.width})"