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

Question:

I am writing a rock, paper and scissors bot for a school project. I keep getting the error in the title (TypeError: randint() takes 3 positional arguments but 4 were given) and I don’t know why. My code is below.

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)   

I’ve said random.randint(1,2,3), which is clearly 3 arguments, not 4. I’m, pretty sure my syntax is correct, but not 100%.

Asked By: user8500190

||

Answers:

random.randint only takes two arguments, a start and an end. The third argument mentioned by Python is self, which is done automatically.

To pick a number between 1 and 3, just do random.randint(1,3).

Those if statements don’t make any sense, by the way; they should look something like:

if userInput == "paper":
    # send discord messages
Answered By: numbermaniac

if you need more than one random number,you can also use numpy.random.randint(start,stop-1,number of randoms)

Answered By: Beryl Amend

I had the same problem, I was building a guess-the-number script, and since I provided all the numbers between 1 and 10. I think you are supposed to format it as random.randit(1,3) instead of listing the variable in between. If you use (1,3) it also accounts for the variable in between those two numbers.

-edit
I did not see that someone already answered this question, if you have anymore questions I am happy to help.

Answered By: HatsuneMikuFan1
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.