-2
I need to receive a matrix and identify if it is an upper triangular matrix, a lower triangular matrix or a diagonal matrix (upper+lower)
I wrote a code initially to find out if it is diagonal (since for me it would be a little easier), but neither it is running, exploring the variables I realize that the counter is not increasing, IE, the function is not running, but the program does not return error anywhere.
Follow the program:
n = int(input())
M = []
for a in range(n):
M.append(input().split(" "))
print(M)
linhas = len(M)
colunas = len(M[0])
cont = 0
for i in range(linhas):
for j in range(colunas):
if i != j and M[i][j] == 0:
cont = cont + 1
if cont == 2*n:
print("diagonal")
To be more readable, try to do a "Ctrl +K" in the code part so you can post here.
– Erick Kokubum
Another detail, your matrix is receiving a string, that is, when you check whether M[i][j] == 0, it will fail, because in fact M[i][j] is "0". To make it easier, just do the following: M.append([int(x) for x in input().split(" ")]), which ai Oce already receives the values as integers.
– Erick Kokubum