Blockquote I need to inheritance a class with less arguments than the parent Blockquote
class Rectangle: def init(self, width, height): #init self.width = width self.height = height
def set_width(self): #just printing
print("The width is: ", self.width)
def set_height(self):
print("The height is: ", self.height)
def get_area(self): #area
area = self.width * self.height
print("The area is: ", area)
def get_perimeter(self): #perimeter
perimeter = 2 * self.width 2 * self.height
print("The perimeter is: ", perimeter)
def get_diagonal(self): #diagonal
diagonal = ((self.width ** 2 self.height ** 2) ** 0.5)
print("the diagonal of the rectangle is: ", round(diagonal,2))
def get_picture(self): #getting the shape
if self.height >= 50 or self.width >= 50:
print("Picture too big!")
print("The picture of the rectangle is:")
for i in range(0,self.height):
print("*"*self.width)
def get_amount_inside(self): #getting the area of the inside of the rectangle
heightInside = self.height-1
widthInside = self.width-1
amountInside = heightInside*widthInside
class Square(Rectangle): # Here. How i do inheritance with less arguments than the parent
def __init__(self, side):
Rectangle.__init__(self, side)
self.side = side
Rect = Rectangle(5,3)
Sq = Square(6)
Rect.set_width()
Rect.set_height()
Rect.get_area()
Rect.get_perimeter()
Rect.get_diagonal()
Rect.get_picture()
Rect.get_amount_inside()
CodePudding user response:
I think you need to do this
super(Square, self).__init__(width=side, height=side)
instead of
Rectangle.__init__(self, side)