Skip to content

Instantly share code, notes, and snippets.

@parzibyte

parzibyte/mayor_menor_matriz.py Secret

Created Nov 27, 2020
Embed
What would you like to do?
"""
https://parzibyte.me/blog
"""
matriz = [
[85, 45, 1, 7, 9],
[12, 52, 9, 151, 56],
[76, 10, 56, 99, 9],
]
# Inicializar y asumir que tanto el mayor como el menor están en el primer elemento; solo para inicializar
mayor = matriz[0][0]
menor = matriz[0][0]
# Momento de recorrer la matriz y obtener el mayor como el menor
for fila in matriz:
for valor in fila:
if valor > mayor:
mayor = valor
if valor < menor:
menor = valor
print("De la matriz: ")
print(matriz)
print(f"El menor es {menor} y el mayor es {mayor}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment