TypeError:randint()有3个位置参数但是给出了4个

时间:2017-10-18 10:49:09

标签: python random

我正在为学校项目写一个摇滚,纸和剪刀机器人。我一直收到标题中的错误({{@root.port_data.name}}),我不知道为什么。我的代码如下。

TypeError: randint() takes 3 positional arguments but 4 were given

我说过if userInput : 'rock' choice = random.randint(1,2,3) if choice == 1: await client.send_message(message.channel, embed=RockEmbed) elif choice == 2: await client.send_message(message.channel, embed=PaperEmbed) elif choice == 3: await client.send_message(message.channel, embed=ScissorsEmbed) if userInput : 'scissors' choice2 = random.randint(1,2,3) if choice2 == 1: await client.send_message(message.channel, embed=RockEmbed) elif choice2 == 2: await client.send_message(message.channel, embed=PaperEmbed) elif choice2 == 3: await client.send_message(message.channel, embed=ScissorsEmbed) if userInput : 'paper' choice3 = random.randint(1,2,3) if choice3 == 1: await client.send_message(message.channel, embed=RockEmbed) elif choice3 == 2: await client.send_message(message.channel, embed=PaperEmbed) elif choice3 == 3: await client.send_message(message.channel, embed=ScissorsEmbed) ,这显然是3个参数,而不是4.我很确定我的语法是正确的,但不是100%。

2 个答案:

答案 0 :(得分:1)

random.randint只接受两个参数,即开始和结束。 Python提到的第三个参数是self,它是自动完成的。

要选择1到3之间的数字,只需执行random.randint(1,3)

顺便说一下,那些if陈述没有任何意义;他们应该看起来像:

if userInput == "paper":
    # send discord messages

答案 1 :(得分:0)

如果需要多个随机数,也可以使用numpy.random.randint(start,stop-1,number of randoms)