2つの必須の位置引数が欠けているというエラーが表示されます: 'height'と 'radius'。私はすべてを試したような気がしますが、私は何か小さいものを見逃していることを知っていますどんな助け? おかげbuiltins.TypeError:__init __()missing 2必要な位置引数: 'height'と 'radius'
# import math
import math
class SodaCan :
# Constructs sodaCan with a given height and radius
# @param height = given height and radius = given radius
def __init__(self, height, radius):
self._height = height
self._radius = radius
# Constructs the volume with the given height and radius
def volume(self):
self._volume = (pi * (self._radius ** 2) * self._height)
# Constructs the Surface Area with the given height and radius
def surfaceArea(self):
self._surfaceArea = (2 * pi * self._radius * self._height) + (2 * pi * (self._radius)**2)
# Return the volume
def getVolume(self):
return self._volume
# Return the Surface Area
def getSurfaceArea(self):
return self._surfaceArea
は、私がここで間違ってやっているのかわからないです。下に私のコードのテストプログラムがあります。あなたはこのような初期化子定義すると
##
# This program test the sodaCan.py
##
# import math so the program can read pi
import math
# from the file folder, ipmort the code from program 'sodaCan'
from sodaCan import SodaCan
mySodaCan = SodaCan()
mySodaCan.height(10)
mySodaCan.radius(4)
print(mySodaCan.getVolume())
print(mySodaCan.getSurfaceArea())
の可能性のある重複した[例外TypeError:受け入れるには(まだ機能)2つの必要な引数が不足している](http://stackoverflow.com/questions/20380276/typeerror-accept-missing-2-required -aduments-still-functional) –
あなたはSodaCanをどのように呼び出しているかを示すことができますか(つまりx = SodaCan(5,4)ですか?)(可能な複製が正しい場合は、さらにコードを表示する必要があります) – Foon