I am writing code for a rock paper scissors game, and when i start writing computer choice with the random function, I get this:
TypeError: randint() missing 1 required positional argument: 'b'
Here’s the code:
import random
ai_choice = random.randint([0, 2])
if int(ai_choice) == 0:
print(rock)
if int(ai_choice) == 1:
print(paper)
if int(ai_choice) == 2:
print(scissors)
I tried looking at the error online but to no avail. I was expecting a normal Rock, Paper, Scissors game.
>Solution :
"Missing positional arguments" means that the function takes more parameters than you provided. When this happens, it can be helpful to look up the documentation to see which parameters you need to pass.
randint()‘s documentation states that it needs two parameters, the start and end point. Instead, you’ve passed both in a list as a single parameter. To fix this, just move them out of the list like this:
ai_choice = random.randint(0, 2)