My code is the following:
import random
matriz=[]
filas=3;columnas=3
def elementos():
for inicializar in range(filas):
matriz.append([0]*columnas)
for i in range(filas):
for j in range(columnas):
matriz[i][j]=random.randint(1,200)
def Mostrar():
print("La matriz es la siguiente:")
for i in matriz:
print(i)
elementos()
mayor=max(item[2] for item in matriz)
print("El valor mas alto generado es el",mayor)
menor=min(item[2] for item in matriz)
print("El valor mas bajo generado es el",menor)
Mostrar()
When showing the matrix, the program is showing the matrix with the 3x3 form but also showing the brackets in each row and "," between each element in the rows, I did not find a solution and I am not going to use any function of the numpy library, My goal is for the program to display the matrix like this:
3 4 5
6 7 8
9 1 2
What you have to do is print one element at a time, not the whole row:
Use
"\t"
quick align values in column. If you want values right-aligned and all columns equal width, that's another question.I put
end=" "
so that heprint
doesn't change lines after printing a value.When you have printed a whole line, you put a
print()
to force a new line.Produces:
You can do it with an itertools method, modify the code but it's what you need.
I noticed that when you wanted to get the min and max in your list it was wrong. If you want to use ramdom() you just have to replace what the randomNumber contains, also put the list as you suggest the result you need. Cheers