Diagonal matrix problem

0

partners could help me with this code I need to print the two diagonals of a matrix and the problem is that it only prints the main diagonal (the one that starts from the left corner)

try:

matriz=[]
matriz2=[]
longitud=3

for a in range(3):
    fila=[]
    for b in range(3):
        numeros=int(input("Digite un numero para la primera lista: "))
        fila.append(numeros)
    matriz.append(fila)

diagonal_secundaria=[]
for e in range(len(matriz)):
    for g in range(len(matriz)):
        numero=matriz[e][g]

        if [e]+[g]==longitud-1:
            diagonal_secundaria.append(numero)

diagonal_primaria=[]
for h in range(len(matriz)):
    for k in range(len(matriz)):
        numero2=matriz[h][k]

        if [h]==[k]:
            diagonal_primaria.append(numero2)


print(diagonal_secundaria)
print(diagonal_primaria)

except ValueError:     print ("The value entered must be numeric")

    
asked by Andress115 05.11.2018 в 19:43
source

0 answers