<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Visualiza el juego de Gato
def visualiza(G):
    V = [" ", "X", "O"]
    print("")
    for i in range(3):
        S = ""
        for j in range(3):
            S = S + V[G[i][j]]
            if j &lt; 2:
                S = S + " | "
        print(S)
        if i &lt; 2:
            print("---------")
    print("")


# Revisa quien gana
def revisa(G):
    for jg in range(1, 3):
        for i in range(3):
            # Horizontal
            if G[i][0] == G[i][1] and G[i][1] == G[i][2] and G[i][2] == jg:
                return jg
            # Vertical
            if G[0][i] == G[1][i] and G[1][i] == G[2][i] and G[2][i] == jg:
                return jg
        # Diagonal
        if G[0][0] == G[1][1] and G[1][1] == G[2][2] and G[2][2] == jg:
            return jg
        # Diagonal
        if G[0][2] == G[1][1] and G[1][1] == G[2][0] and G[2][0] == jg:
            return jg
    # Revisa si todavia se puede tirar
    for i in range(3):
        for j in range(3):
            if G[i][j] == 0:
                return 0
    # Se hizo Gato
    return 3


# Controla el juego de gato
def Juego():
    G = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
    visualiza(G)
    # Pregunta al usuario con que desea jugar
    while 1:
        jg = int(input("Con que quieres tirar 1(X) y 2(O)?: "))
        if jg &gt;= 1 and jg &lt;= 2:
            break
        else:
            print("Numero fuera de rango")
    # Ciclo del juego del gato
    while 1:
        r = c = 0
        # Solicita la tirada al jugador en turno
        print("Por favor tira jugador: " + str(jg))
        while 1:
            r = int(input("Dame el renglon?: "))
            c = int(input("Dame la columna?: "))
            if r &gt;= 0 and r &lt; 3 and c &gt;= 0 and c &lt; 3:
                if G[r][c] == 0:
                    break
                else:
                    print("Casilla ocupada")
            else:
                print("fuera de rango")
        # Tirada valida
        G[r][c] = jg
        visualiza(G)
        # Revisa quien gano
        r = revisa(G)
        if r == 1:
            print("Gano 1")
            return
        if r == 2:
            print("Gano 2")
            return
        if r == 3:
            print("Gato")
            return
        # Cambia para que tire el siguiente jugador
        jg = jg + 1
        if jg &gt; 2:
            jg = 1


# Lanza el juego de Gato
Juego()
</pre></body></html>