-1
我正在爲學校項目編寫一個岩石,紙和剪刀機器人。我不斷收到標題中的錯誤(TypeError: randint() takes 3 positional arguments but 4 were given
),我不知道爲什麼。我的代碼如下。TypeError:randint()需要3個位置參數,但有4個被給出
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)
我說random.randint(1,2,3)
,這顯然是3個參數,而不是4.我,很肯定我的語法是正確的,但不是100%。
請注意'random.randint()'是一個方法,它有一個'self'參數作爲參數之一。如果您傳入3個參數,則總共有4個參數。閱讀[函數文檔](https://docs.python.org/3/library/random.html#random.randint)以查看它接受的參數。 –
質量過濾器是有原因的。你的解決方法不被讚賞。你不需要發佈太多的代碼;只是'random.randint(1,2,3)'已經顯示錯誤。 –
我鏈接的文檔非常清楚該函數的功能。你不能傳入3個參數。使用'random.randint(1,3)'或使用'random.choice([1,2,3])'。 –