我正在尝试遍历列表中的两个元素(整数),并且对于列表中的每个元素,如果值等于整数,我想用字符串替换元素。我究竟做错了什么?
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
慕森卡
智慧大石
小唯快跑啊
相关分类