Typeerror: randint() Missing 1 required positional argument: 'b'

Asked

Viewed 528 times

1

My code is super simple:

import random
jogador=int(input('Qual é a sua jogada?\n1 - Pedra\n2 - Papel\n3 - Tesoura\nEu jogo: '))
jogador=random.randint(jogador)
print('O computador joga {}'.format(jogador))

But it keeps giving this error that is in the title. I do not know what is this argument 'b'.

1 answer

3

According to the documentation, randint receives two parameters: a and b. The first indicates the minimum value and the second indicates the maximum value. In your code you are only passing one parameter (the variable jogador).

But in your case, what you need seems to be:

jogada = random.randint(1, 3)

That is, it will generate a random number between 1 and 3.


Not directly related, but if one move is from the player and another from the computer, it makes no sense to store both in the same variable. Maybe what you want is something like:

import random
jogador = int(input('Qual é a sua jogada?\n1 - Pedra\n2 - Papel\n3 - Tesoura\nEu jogo: '))
computador = random.randint(1, 3)
print('O computador joga {}'.format(computador))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.