Repository navigation
Expand file tree
/
Copy pathrectangle.py
More file actions
80 lines (65 loc) · 2.09 KB
/
Copy pathrectangle.py
File metadata and controls
80 lines (65 loc) · 2.09 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
76
77
78
79
80
#coding:utf-8
'''
filename: rectangle.py
'''
class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length * self.width
def perimeter(self):
return 2 * self.length + 2 * self.width
# class Square:
# def __init__(self, length):
# self.length = length
# def area(self):
# return self.length * self.length
# def perimeter(self):
# return 4 * self.length
class Square(Rectangle):
def __init__(self, length):
super().__init__(length, length)
class Cube(Square):
def surface_area(self):
face_area = super().area()
return face_area * 6
def volume(self):
face_area = super().area()
return face_area * self.length
class Triangle:
def __init__(self, base, height):
self.base = base
self.height = height
def area(self):
return 0.5 * self.base * self.height
# class RightPyramid(Square, Triangle):
# def __init__(self, base, slant_height):
# self.base = base
# self.slant_height = slant_height
# super().__init__(self.base)
# self.height = slant_height
# def area(self):
# base_area = super().area()
# #perimeter = super().perimeter()
# tri_area = Triangle.area(self)
# #return 0.5 * perimeter * self.slant_height + base_area
# return tri_area * 4 + base_area
class RightPyramid(Triangle, Square):
def __init__(self, base, slant_height):
self.base = base
self.slant_height = slant_height
Square.__init__(self, self.base)
Triangle.__init__(self, self.base, self.slant_height)
def area(self):
base_area = super(Square, self).area()
#perimeter = super().perimeter()
tri_area = Triangle.area(self)
#return 0.5 * perimeter * self.slant_height + base_area
return tri_area * 4 + base_area
if __name__ == "__main__":
# cube = Cube(2)
# print(cube.surface_area())
# print(cube.volume())
pyramid = RightPyramid(2, 4)
print(pyramid.area())