Skip to content

Commit bf9e9fd

Browse files
authored
Create polygon-area-calculator.py
1 parent 382452e commit bf9e9fd

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

polygon-area-calculator.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class Rectangle:
2+
def __init__(self, width, height):
3+
self.width = width
4+
self.height = height
5+
def set_width(self, width):
6+
self.width=width
7+
def set_height(self, height):
8+
self.height = height
9+
def get_diagonal(self):
10+
return (self.width ** 2 + self.height ** 2) ** .5
11+
def get_area(self):
12+
return self.width * self.height
13+
def get_perimeter(self):
14+
return 2 * self.width + 2 * self.height
15+
def get_picture(self):
16+
if self.width > 50 or self.height > 50:
17+
return "Too big for picture."
18+
mystr = ""
19+
for i in range (0, self.height):
20+
for j in range (0, self.width):
21+
mystr = mystr + "*"
22+
mystr = mystr + "\n"
23+
return mystr
24+
def __str__(self):
25+
return "Rectangle(width=" + str(self.width) + ", height=" + str(self.height) + ")"
26+
def get_amount_inside(self, obj):
27+
return int((self.height*self.width)/(obj.height*obj.width))
28+
29+
class Square(Rectangle):
30+
def __init__(self, side):
31+
super().__init__(side, side)
32+
def set_side(self, side):
33+
self.height = side
34+
self.width = side
35+
def __str__(self):
36+
return "Square(side=" + str(self.height) +")"
37+
def set_width(self, width):
38+
self.height = width
39+
self.width = width
40+
def set_height(self, height):
41+
self.height = height
42+
self.width = height

0 commit comments

Comments
 (0)