__init __()缺少1个必需的位置参数:'值'

时间:2016-02-03 02:24:09

标签: python

我不明白出了什么问题。我一直认为我错过了必要的位置论证。

class CoinToss(object):

    def __init__(self, flip, ID_Num, Value):
        self.flip = flip
        self.ID_Num = ID_Num
        self.Value = Value

    def Flip(self):
        """
        Method is important in determining the number of flips and simulating the coin
        """
        data = []
        Num_flip = int(input("how many times do you want to flip the coin? :"))
        print("the ball at the start: ball: d%, state: d% value: d% " %(self.ID_Num))
        for i in range(Num_flip):
            self.flip = self.flip = 1
            if randint(0,1) == 0:
                self.Value = self.Value + 1
                data.append(self.value)

            else:
                self.Value = self.Value - 1
                data.append(self.Value)

1 个答案:

答案 0 :(得分:2)

显然,当您使用CoinToss时,只需使用2个参数flipID_NUM来调用它。这会导致错误,因为您未向CoinToss.__init__()提供所需的Value参数。

相关问题