First thing you need to notice is that the creation of the matrix is wrong, you need to add a new line after you have already inserted values in her four positions, for this the line m.append(linha)
needs to be out of second for
.
Find the highest value is simple, just use the function max
combined with comprehensilist on, basically, a new collection is created (linear, this time) with all the elements (without worrying about its lines and columns) and in this linear collection is sought the highest value.
maior = max([valor for linha in m for valor in linha])
But since you need to find his contents (row and column), I made a code that goes through all the elements, checks which is the largest and stores his row and column.
Is there a simpler way to do it, since Python has this philosophy of being simplistic? Most likely yes, but I have no idea what it would be like
m = []
for i in range(4):
linha = []
for j in range(4):
linha.append(int(input()))
m.append(linha)
maior_linha = 0
maior_coluna = 0
maior = m[0][0]
for l in range(4):
for c in range(4):
if maior < m[l][c]:
maior = m[l][c]
maior_linha = l
maior_coluna = c
print('linha do maior: {}\ncoluna do maior: {}'.format(maior_linha, maior_coluna))
See working on repl.it.
It is really a good thing to give the answer to the homework instead of giving the means to reach the solution?
– ppalacios
@ppalacios I explained everything that is done, if he wants to study will read the code and my explanation and if you have doubts can comment or even go on chat and talk to me. If he doesn’t want to learn there are 1001 ways to get the result anyway, it won’t be a Sopt response that will prevent this. In addition, the AP showed that it is stopped at the given point and that it needs help, at no time the question seemed to me a "do it for me".
– Jéf Bueno