Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的字典不能用python更新_Python - Fatal编程技术网

为什么我的字典不能用python更新

为什么我的字典不能用python更新,python,Python,在我的代码中,我尝试使用play函数使用用户输入更新dic中的值。但是值(\t)没有被输入的值更新。为什么?我怎样才能解决这个问题 dic = {7: "\t", 8:"\t", 9: "\t", 4: "\t", 5: "\t", 6: "\t", 1:"\t", 2: "\t&qu

在我的代码中,我尝试使用play函数使用用户输入更新dic中的值。但是值(\t)没有被输入的值更新。为什么?我怎样才能解决这个问题

    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版本?非常感谢。非常感谢。你太棒了