__init_yu()缺少1个必需的位置参数:“Value”

2024-06-02 08:53:02 发布

您现在位置: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)

Tags: theinselfiddatavaluedefnum
1条回答
网友
1楼 · 发布于 2024-06-02 08:53:02

显然,当您使用CoinToss时,您只使用两个参数来调用它,flip和{}。这将导致错误,因为您没有为CoinToss.__init__()提供必需的Value参数。在

相关问题 更多 >