各路大神,今天下午在学习Python3.12 多继承的时候,有个构造方法一直报错,希望大家能帮忙瞅瞅,求求了~~~~~~~
代码如下:
点击查看代码
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def area(self):
return self.width * self.height
def perimeter(self):
return 2 * self.width + 2 * self.height
class Square(Rectangle):
def __init__(self, side):
super().__init__(side, side)
class Cube(Square):
def surface_area(self):
return self.area() * 6
def vilume(self):
return self.area() * self.width
class Triangle:
def __int__(self, base, height):
self.base = base
self.height = height
def area(self):
return self.base * self.height * 0.5
class RightPyramid(Square, Triangle):
def __int__(self, low_base, slant_height):
self.low_base = low_base
self.slant_height = slant_height
super().__int__(self.low_base)
def surface_area(self):
s = super().area()
p = super().perimeter()
return s + p * self.slant_height * 0.5
if __name__ == '__main__':
d = RightPyramid(2,4)
print(d.surface_area())
防吞图原因描述:TypeError: Square.init() takes 2 positional arguments but 3 were given
标签:__,构造方法,area,python,self,height,base,报错,def From: https://www.cnblogs.com/JiaoHAAA/p/18146441