main() で属性エラーが発生しています。誰かが私を助けてくれますか?これは私のクラスです:
インポート数学
クラス Cylinder2():
def __init__(self, cylRadius = 1, cylHeight = 1):
self.__radius = cylRadius
self.__height = cylHeight
def getPerimeter(self):
return (2 * math.pi * self.__radius)
def getEndArea(self):
return (math.pi * (self.__radius ** 2))
def getSideArea(self):
return (2 * (math.pi * (self.__radius * (self.__height))))
def getSurfaceArea(self):
return (2 * (math.pi * (self.__radius) * (self.__height + self.__radius)))
def getVolume(self):
return (math.pi * (self.__radius ** 2) * self.__height)
def setRadius(self, r):
self.__radius = r
def setHeight(self, h):
self.__height = h
def getRadius(self):
return self.__radius
def getHeight(self):
return self.__height
これは main() です:
CylinderModule2 インポートから *
デフメイン():
bottle = Cylinder2(4, 8)
bottle.setRadius(2)
bottle.setHeight(4)
print("The radius and height of the bottle are: ", bottle.__radius, " and ", bottle.__height)
print("The perimeter of the bottle end circle is", ("%.2f" % bottle.getPerimeter()))
print("The end circle area of the bottle is ", ("%.2f" % bottle.getEndArea()))
print("The side area of the bottle is ", ("%.2f" % bottle.getSideArea()))
print("The total surface of the bottle is ", ("%.2f" % bottle.getSurfaceArea()))
print("The volume of the bottle is ", ("%.2f" % bottle.getVolume()))
主要()
これは私が得るエラーです: print("The radius and height of the bottle are: ", bottle._ radius, " and ", bottle. _height) AttributeError: 'Cylinder2' object has no attribute '__radius'