错误:choice()接受2个位置参数,但给出了4个

2024-06-16 13:59:25 发布

您现在位置:Python中文网/ 问答频道 /正文

def strategy(board):
    import random
    #t_1 =, t_2 and t_3 are ranges from 0 to a object named board
    t_1 = [board[0] - i for i in range (0,(board[0] + 1))]
    t_2 = [board[1] - i for i in range (0,(board[1] + 1))]
    t_3 = [board[2] - i for i in range (0,(board[2] + 1))]

    #randomly chooses a single number from each range
    x = random.choice (t_1)
    y = random.choice (t_2)
    z = random.choice (t_3)

    #randomly chooses one of those 3 randomly chosen numbers
    q = random.choice (x,y,z)

如您所见,代码从3个不同的范围中随机选择一个数字,并将它们分配给不同的变量。一旦完成,它会从之前选择的3个数字中随机选择一个,并分配一个新的变量。 我一直收到标题中提到的错误。我想不出出什么事了。 谢谢你的帮助 附笔 我正在使用python3和PyCharm


Tags: andinfromimportboardfordefrange