I am trying to loop through two elements in a list (integers) and for each element in the list if the value is equal to the integer, I want to replace the element with the string. What am I doing wrong?
players = [np.random.randint(1, 4), np.random.randint(1, 4)]
for i in players:
if i == 1:
players[i] = 'rock'
elif i == 2:
players[i] = 'scissors'
elif i == 3:
players[i] = 'paper'
player_1 = players[0]
computer = players[1]
print(player_1)
print(computer)
Actual:
scissors
1
or, I get this error:
Traceback (most recent call last):
enter Player 1's choice:
File "...", line 12, in <module>
players[i] = 'scissors'
enter Player 2's choice:
IndexError: list assignment index out of range
Expected
scissors
rock
iis not the index it is actually the element inside the list. try enumerate or simply userange(len(players))rather thanplayers