-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuper.py
38 lines (27 loc) · 828 Bytes
/
Super.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
#https://realpython.com/python-super/
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
# Here we declare that the Square class inherits from the Rectangle class
class Square(Rectangle):
def __init__(self, length):
super().__init__(length, length)
square = Square(4)
print(square.area())
rectangle = Rectangle(2,4)
print(rectangle.area())
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
cube = Cube(3)
print(cube.surface_area())
print(cube.volume())