class GeometricObject:
def __init__(self,color = 'green',filled='true'):
self.__color=color
self.__filled=filled
def getColor(self):
return self.__color
def setColor(self,color):
self.__color=color
def isFilled(self):
return self.__filled
def setFilled(self,filled):
self.__filled=filled
def __str__(self):
return "Color: " + self.__color + " Filled: " + str(self.__filled)
這是三角類:__init __()1至3個位置參數需要但4分別給予
from GeometricObject import GeometricObject
class Triangle(GeometricObject):
def __int__(self,side1=1.0,side2=1.0,side3=1.0):
super().__init__()
self.__side1=side1
self.__side2=side2
self.__side3=side3
def getPerimeter(self):
return self.__side1 + self.__side2 + self.__side3
def __str__(self):
return super().__str__()+" side 1: "+str(self.__side1)+" side 2: "+str(self.__side2)+" side 3: "+str(self.__side3)
from triangle import Triangle
from GeometricObject import GeometricObject
def main():
side1=int(input("Enter first side: "))
side2=int(input("Enter second side: "))
side3=int(input("Enter third side: "))
t1=Triangle(side1,side2,side3)
print(t1.getColor())
print(t1.getPerimeter())
print(t1.__str__())
main()
當我創建在主函數的三角形對象T1中的誤差是發生: 初始化()從1到3的位置參數,但4分別給予需要...
我知道有關於這樣類似的錯誤,其他職位,但如果你提供的參數不夠他們中的很多人與一個人的那提供了provi太多的爭論並沒有回答我的問題。
[TypeError:\ _ \ _ init \ _ \ _()只需要1個參數(給定3)pyXML](http://stackoverflow.com/questions/11905148/typeerror-init-takes-exactly- 1-argument-3-given-pyxml) – Johnsyweb