0

Here in my code, I am trying to update values in dic with user input using the play function. But the values(\t) is not getting updated by inputted value. Why? how can I fix this?

    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()

1 Answers1

1

pos = input() would be a str, not int. Try changing it to pos = int(input())

abe
  • 957
  • 5
  • 10