Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions entrada.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def ingresar_matriz():
"""Función para ingresar una matriz por teclado"""
while True:
try:
filas = int(input("Ingrese el número de filas: "))
if filas < 1:
raise ValueError
columnas = int(input("Ingrese el número de columnas: "))
if columnas < 1:
raise ValueError
break
except ValueError:
print("Error: la cantidad de filas y columnas deben ser numeros enteros positivos.")
matriz = []
for i in range(filas):
while True:
try:
fila = list(map(float, input(f"Ingrese la fila {i+1} separada por espacios: ").split()))
if len(fila) != columnas:
print(f"Error: debe ingresar exactamente {columnas} valores.")
else:
matriz.append(fila)
break
except ValueError:
print("Error: debe ingresar solo números.")
return matriz

def imprimir_matriz(matriz):
"""Función para imprimir una matriz"""
try:
for i in range(len(matriz)):
print(matriz[i])
except TypeError or ValueError:
return None