-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape_calculator.py
64 lines (49 loc) · 1.64 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
63
64
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
# Setter function (width)
def set_width(self, width):
self.width = width
# Setter function (height)
def set_height(self, height):
self.height = height
# Get Area of the shape
def get_area(self):
return self.width * self.height
# Get Perimeter of the shape
def get_perimeter(self):
return (2 * self.width) + (2 * self.height)
# Get Diagonal
def get_diagonal(self):
return ((self.width**2 + self.height**2)**.5)
# Get (*) picture
def get_picture(self):
if self.height > 50 or self.width > 50:
return "Too big for picture."
else:
return ((("*" * self.width) + "\n") * self.height)
# Get No of shape(Sqaure| Rectangle) can occupy in the given Shape
def get_amount_inside(self, obj):
return (self.width // obj.width) * (self.height // obj.height)
# String representation of Object
def __str__(self):
return (("Rectangle(width={0}, height={1})").format(
self.width, self.height))
class Square(Rectangle):
def __init__(self, side):
self.height = side
self.width = side
# Setter Function (side)
def set_side(self, side):
self.height = side
self.width = side
# Setter function (width)
def set_width(self, side):
self.width = side
# Setter function (height)
def set_height(self, side):
self.height = side
# String representation of Object
def __str__(self):
return f"Square(side={self.width})"