0
import random
class Mapa:
    def __init__(self):
        self.mapa = [["_ ","_ ","_ "],["_ ","_ ","_ "],["_ ","_ ","_ "]]
        self.livres = 9
    def imprime_mapa(self):
        for i in range(len(self.mapa)):
            for j in range(len(self.mapa[0])):
                print(self.mapa[i][j],end=" ")
            print()
    def jogador_escolhe(self,L):
        print("Sua vez... ")
        l = int(input("Escolha a linha: ")) - 1
        c = int(input("Escolha a coluna: ")) - 1
        print("l =",l,"e c = ",c)
        while l < 0 or l > 2 or c < 1 or c > 2 or self.mapa[l][c] != "_ ":
            print("Escolha uma posição válida... ")
            l = int(input("Escolha a linha: ")) - 1
            c = int(input("Escolha a coluna: ")) - 1
            print("l =",l,"e c = ",c)
        self.mapa[l][c] = "x "
        L = L -1
        if L == 0 or self.checar_se_ganhou():
            self.imprime_mapa()
            self.fim_de_jogo()
        else:
            self.imprime_mapa()
            self.computador_escolhe(L)
        
    def computador_escolhe(self,L):
        print("É a vez do computador...")
        l = random.randrange(3)
        c = random.randrange(3)
        print("l =",l,"e c = ",c)
        while l < 0 or l > 2 or c < 1 or c > 2 or self.mapa[l][c] != "_ ":
            l = random.randrange(3)
            c = random.randrange(3)
            print("l =",l,"e c = ",c)
        self.mapa[l][c] = "0 "
        L = L - 1
        if L == 0 or self.checar_se_ganhou():
            self.imprime_mapa()
            self.fim_de_jogo()
        else:
            self.imprime_mapa()
            self.jogador_escolhe(L)
    def fim_de_jogo(self):
        print("Fim de jogo.")
    def checar_se_ganhou(self):
        #status = False
        if [self.mapa[0][0] , self.mapa[0][1], self.mapa[0][2]] == ["x ","x ","x "]:
            print("Você ganhou!")
            return True
        elif [self.mapa[0][0] , self.mapa[0][1], self.mapa[0][2]] == ["0 ","0 ","0 "]:
            print("O Computador ganhou!")
            return True
        elif [self.mapa[1][0] , self.mapa[1][1], self.mapa[1][2]] == ["x ","x ","x "]:
            print("Você ganhou!")
            return True
        elif [self.mapa[1][0] , self.mapa[1][1], self.mapa[1][2]] == ["0 ","0 ","0 "]:
            print("O Computador ganhou!")
            return True
        elif [self.mapa[2][0] , self.mapa[2][1], self.mapa[2][2]] == ["x ","x ","x "]:
            print("Você ganhou!")
            return True
        elif [self.mapa[2][0] , self.mapa[2][1], self.mapa[2][2]] == ["0 ","0 ","0 "]:
            print("O Computador ganhou!")
            return True
        elif [self.mapa[0][0] , self.mapa[1][0], self.mapa[2][0]] == ["x ","x ","x "]:
            print("Você ganhou!")
            return True
        elif [self.mapa[0][0] , self.mapa[1][0], self.mapa[2][0]] == ["0 ","0 ","0 "]:
            print("O Computador ganhou!")
            return True
        elif [self.mapa[0][1] , self.mapa[1][1], self.mapa[2][1]] == ["x ","x ","x "]:
            print("Você ganhou!")
            return True
        elif [self.mapa[0][1] , self.mapa[1][1], self.mapa[2][1]] == ["0 ","0 ","0 "]:
            print("O Computador ganhou!")
            return True
        elif [self.mapa[0][2] , self.mapa[1][2], self.mapa[2][2]] == ["x ","x ","x "]:
            print("Você ganhou!")
            return True
        elif [self.mapa[0][2] , self.mapa[1][2], self.mapa[2][2]] == ["0 ","0 ","0 "]:
            print("O Computador ganhou!")
            return True
        elif [self.mapa[0][0] , self.mapa[1][1], self.mapa[2][2]] == ["x ","x ","x "]:
            print("Você ganhou!")
            return True
        elif [self.mapa[0][0] , self.mapa[1][1], self.mapa[2][2]] == ["0 ","0 ","0 "]:
            print("O Computador ganhou!")
            return True
        elif [self.mapa[0][2] , self.mapa[1][1], self.mapa[2][0]] == ["x ","x ","x "]:
            print("Você ganhou!")
            return True
        elif [self.mapa[0][2] , self.mapa[1][1], self.mapa[2][0]] == ["0 ","0 ","0 "]:
            print("O Computador ganhou!")
            return True
        else:
            return False
jogo = Mapa()
print("Bem vindo ao Jogo da velha!")
print("Vamos sortear quem começa....")
jogo.imprime_mapa()
if random.randrange(0,2) == 0:
    print("Você  começa!")
    jogo.jogador_escolhe(9)
else:
    print("Computador começa!")
    jogo.computador_escolhe(9)
detail the problem better. occurs an error or just does not do something you expected? if it is an error, what error message? and in what part of the code? I think you put too much information in the question title but lacked explanation in the body of the question.
– phduarte
The other day I was insomnia and I did in python one tic-tac-toe (complete). Maybe it’ll help him. Testing on the COLAB
– Augusto Vasques
when trying to select the positions cited in the title it simply does not accept and prompts new choice. No error message.
– Tiago Levi Pacheco