def player_move(Player, board):
playerMarker = None
print("Player ",Player," it is your turn!")
playerChoice = input("Please input your move: ")
if Player == 1:
playerMarker == 9
else:
playerMarker == 10
board[playerChoice] == playerMarker
這會產生類型錯誤:不明原因類型錯誤的列表
line 36, in player_move
board[playerChoice] == playerMarker
TypeError: list indices must be integers or slices, not str
這是爲什麼,我怎麼能阻止這種從occouring?我明白str不能添加到這個列表中,但是我不是試圖添加整數嗎?
'input()'返回的值是'str'類型。你需要將它轉換爲'int'來將其轉換爲有效的索引。此外,字符串應該保存有效的整數值。 –