Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python __init_u3;()缺少1个必需的位置参数:“Value”_Python - Fatal编程技术网

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

Python __init_u3;()缺少1个必需的位置参数:“Value”,python,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 determini

我不明白怎么了。我一直觉得我缺少一个必要的位置参数

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)

显然,当您使用cointost时,您只使用两个参数flip和ID_NUM调用它。这会导致错误,因为您没有提供cointost。u_init_u_u_____________________________________。只需检查您传递给它的参数有多少,您缺少一个。我找不到我传递给它的参数。a我遗漏了一些简单的东西?你首先在哪里创建Cointost对象?我猜您误解了Python初始值设定项的工作原理,并使用了cointosx。当您应该使用cointosx,y,z创建实例,然后将其作为第一个参数隐式传递时,它不会隐式创建实例并将其作为自身传递。这里还有一些令人困惑的设计。您将flip传递给初始值设定项,但您认为该类似乎是用于执行flip的;self.flip充其量只能指示是否发生了翻转—在flip中设置为1,但要求调用方传递它意味着该值没有用处;他们可能会说它翻了,但它没有翻。我在main中调用它:for tails self.Value=self.Value-1 data.appendself.Value printafter flip:%d,ball:%d,state:%d,Value:%d%i,self.ID\u Num,self.Value=data printself.Value def main:coin=cointoss1100 coin.flip main如何提供参数值?我不确定此代码的作用,但看起来您应该根据您想要的是正面还是反面为其提供0或1。顺便说一下,如果randint0,1==0:self.Value=self.Value+1 data.appendself.Value追加不存在的self.Value。它应该是data.appendself.Value。此外,for循环的第一行是self.flip=self.flip=1。它可以简化为self.flip=1。
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)