Connect 4 add element from User in LIST PYTHON

28 Views Asked by At

I have created the matrix, but when the data entered by the user is added the board loses the initial structure

I need the board to continue printing in the same format as when the game starts.

This is the code:

tablero = []
NUM_FILAS = 6
NUM_COLUM = 7
jugador = 1


for fila in range(NUM_FILAS):
    filas = []
    for j in range(NUM_COLUM):
        filas.append([])
    tablero.append(filas)

print("\nJueguemos CONECTA 4\n")
for i in range(6):
    for j in range(7):
        print(tablero[i][j], end=" ")
    print()

while True:
    
    usuario = input('Jugador, elige una columna: ')
    if usuario.isdigit():
        usuario = int(usuario)
        
        for pos in tablero:
             if usuario == 1:
                tablero.append([jugador])
                print(tablero)
                break

else:
    print('El juego solo funciona con numeros')   

OUTPUT

0

There are 0 best solutions below