我正在尝试使用python上的类,我还试图使用super((__init__命令来继承所有值在上一节课中,只是它在编译时给了我一个错误,我不知道如何将代码系统化。代码是可执行的!有人能向我解释一下我做错了什么以及怎么做错的吗?提前非常感谢。
class rectangle:
def __init__(self, length, height):
self.length = length
self.height = height
def area(self):
return self.length * self.height
def perimeter(self):
return (self.length *2) + (self.height *2)
class square(rectangle):
def __init__(self, length):
super().__init__(rectangle, self)
rett_1 = rectangle("12","3")
print(rectangle.area(rett_1))
python给我的错误也是:
return self.length * self.height
TypeError:无法将序列与类型为"str"的非int相乘
基本上答案在代码的最后部分:
rett_1 = rectangle(12, 3)
print(rectangle.area(rett_1))
我不得不删除"在我要插入的号码上。