Advertisement
simeonshopov

Super

May 29th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. class Rectangle:
  2.     def __init__(self, length, width, **kwargs):
  3.         self.length = length
  4.         self.width = width
  5.         super().__init__(**kwargs)
  6.  
  7.     def area(self):
  8.         return self.length * self.width
  9.  
  10.     def perimeter(self):
  11.         return 2 * self.length + 2 * self.width
  12.  
  13. # Here we declare that the Square class inherits from
  14. # the Rectangle class
  15. class Square(Rectangle):
  16.     def __init__(self, length, **kwargs):
  17.         super().__init__(length=length, width=length, **kwargs)
  18.  
  19. class Cube(Square):
  20.     def surface_area(self):
  21.         face_area = super().area()
  22.         return face_area * 6
  23.  
  24.     def volume(self):
  25.         face_area = super().area()
  26.         return face_area * self.length
  27.  
  28. class Triangle:
  29.     def __init__(self, base, height, **kwargs):
  30.         self.base = base
  31.         self.height = height
  32.         super().__init__(**kwargs)
  33.  
  34.     def tri_area(self):
  35.         return 0.5 * self.base * self.height
  36.  
  37. class RightPyramid(Square, Triangle):
  38.     def __init__(self, base, slant_height, **kwargs):
  39.         self.base = base
  40.         self.slant_height = slant_height
  41.         kwargs["height"] = slant_height
  42.         kwargs["length"] = base
  43.         super().__init__(base=base, **kwargs)
  44.  
  45.     def area(self):
  46.         base_area = super().area()
  47.         perimeter = super().perimeter()
  48.         return 0.5 * perimeter * self.slant_height + base_area
  49.  
  50.     def area_2(self):
  51.         base_area = super().area()
  52.         triangle_area = super().tri_area()
  53.         return triangle_area * 4 + base_area
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement