0

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%.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
  • 1
    Note that `random.randint()` is a method, which has a `self` argument that counts as one of the arguments. If you are passing in 3 arguments, that makes it 4 in total. Read the [function documentation](https://docs.python.org/3/library/random.html#random.randint) to see what arguments it accepts. – Martijn Pieters Oct 18 '17 at 10:51
  • 2
    That quality filter is there for a reason. Your work-around is not appreciated. You didn't need to post that much code; simply `random.randint(1, 2, 3)` already shows the error. – Martijn Pieters Oct 18 '17 at 11:00
  • The documentation I linked to is pretty clear on what the function does. You can't pass in 3 arguments. Either use `random.randint(1, 3)` or use `random.choice([1, 2, 3])`. – Martijn Pieters Oct 18 '17 at 11:02
  • Your `if` statements do not do what you want them to do; they all are true if `userInput` is a non-empty string, followed by a string object that is ignored. You could remove each of your `if userInput ...` lines and your program would do exactly the same thing. – Martijn Pieters Oct 18 '17 at 11:03
  • 1
    You only have to make the choice **once**, then pick responses based on the user input (use `if userInput == 'rock':`, etc.) – Martijn Pieters Oct 18 '17 at 11:04

3 Answers3

4

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
numbermaniac
  • 788
  • 1
  • 13
  • 28
3

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

Beryl Amend
  • 131
  • 1
  • 9
0

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.

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/32928884) – Nikita Shabankin Oct 17 '22 at 13:16