为什么我的字典不能用python更新
在我的代码中,我尝试使用play函数使用用户输入更新dic中的值。但是值(\t)没有被输入的值更新。为什么?我怎样才能解决这个问题为什么我的字典不能用python更新,python,Python,在我的代码中,我尝试使用play函数使用用户输入更新dic中的值。但是值(\t)没有被输入的值更新。为什么?我怎样才能解决这个问题 dic = {7: "\t", 8:"\t", 9: "\t", 4: "\t", 5: "\t", 6: "\t", 1:"\t", 2: "\t&qu
dic = {7: "\t",
8:"\t",
9: "\t",
4: "\t",
5: "\t",
6: "\t",
1:"\t",
2: "\t",
3: "\t"}
player1 = "null"
player2 = "null"
#player 1 is true and player 2 is false
playerOnesTurn = True
def printBoard():
print(dic[7]+ "|" +dic[8]+ "|"+ dic[9])
print(dic[4]+ "|"+dic[5]+ "|"+ dic[6])
print(dic[1]+ "|"+dic[2]+ "|"+ dic[3])
def play():
if(playerOnesTurn):
print(player1 + "'s turn")
print("Enter the position: ")
pos = input() # it is an int value
dic[pos] = "X"
play()
printBoard()
pos=input()
将是一个str
,而不是int
。尝试将其更改为pos=int(input())
您使用的是哪个python版本?非常感谢。非常感谢。你太棒了