0% encontró este documento útil (0 votos)
40 vistas9 páginas

Programacion Taller 9

El documento presenta una serie de ejercicios de programación en Python relacionados con matrices y diccionarios.

Cargado por

8xd4sx7967
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
40 vistas9 páginas

Programacion Taller 9

El documento presenta una serie de ejercicios de programación en Python relacionados con matrices y diccionarios.

Cargado por

8xd4sx7967
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd

EJERCICIO 1

def es_matriz_identidad(matriz):

n = len(matriz)

if n != len(matriz[0]):

return False

for i in range(n):

for j in range(n):

if i == j:

if matriz[i][j] != 1:

return False

else:

if matriz[i][j] != 0:

return False

return True

N = int(input())

matriz = []

for i in range(N):

fila = []

for j in range(N):

num = int(input())

fila.append(num)

matriz.append(fila)
if es_matriz_identidad(matriz):

print("Matriz identidad")

else:

print("Matriz no identidad")

EJERCICIO 2

def es_matriz_diagonal(matriz):

n = len(matriz)

for i in range(n):

for j in range(n):

if i != j and matriz[i][j] != 0:

return False

return True

n = int(input())

matriz = []

for i in range(n):

fila = []

for j in range(n):

elemento = int(input())

fila.append(elemento)

matriz.append(fila)

if es_matriz_diagonal(matriz):

print("Matriz diagonal")
else:

print("Matriz no diagonal")

EJERCICIO 3

def es_matriz_escalar(matriz):

N = len(matriz)

for i in range(N):

for j in range(N):

if i == j and matriz[i][j] != matriz[0][0]:

return False

if i != j and matriz[i][j] != 0:

return False

return True

N = int(input())

matriz = []

for i in range(N):

fila = []

for j in range(N):

elemento = int(input())

fila.append(elemento)

matriz.append(fila)

if es_matriz_escalar(matriz):

print("Matriz escalar")

else:

print("Matriz no escalar")
EJERCICIO 4

def es_triangular_superior(matriz):

n = len(matriz)

for i in range(n):

for j in range(0, i):

if matriz[i][j] != 0:

return False

return True

def es_triangular_inferior(matriz):

n = len(matriz)

for i in range(n):

for j in range(i + 1, n):

if matriz[i][j] != 0:

return False

return True

def main():

n = int(input())

matriz = []

for i in range(n):

fila = []

for j in range(n):

elemento = int(input())

fila.append(elemento)

matriz.append(fila)

if es_triangular_superior(matriz):
print("Triangular superior")

elif es_triangular_inferior(matriz):

print("Triangular inferior")

else:

print("No es triangular superior ni inferior")

if __name__ == "__main__":

main()

EJERCICIO 5

def es_bandera_escocia(tabla):

n = len(tabla)

if tabla[0][0] != '0':

return False

for fila in tabla:

if len(fila) != n:

return False

for i in range(n):

if tabla[i][i] != '0':

return False

for i in range(n):

if tabla[i][n - 1 - i] != '0':

return False

for i in range(n):

for j in range(n):
if i != j and i != n - 1 - j and tabla[i][j] != '*':

return False

return True

n = int(input())

tabla = []

for _ in range(n):

fila = input().split()

tabla.append(fila)

if es_bandera_escocia(tabla):

print("Si es la bandera de Escocia")

else:

print("No es la bandera de Escocia")

EJERCICO 6

def producto_fila(fila):

producto = 1

for elemento in fila:

producto *= elemento

return producto

M = int(input())

N = int(input())

matriz = []

for i in range(M):

fila = []

for j in range(N):
elemento = int(input())

fila.append(elemento)

matriz.append(fila)

mayor_producto = float('-inf')

posicion_mayor = 0

menor_producto = float('inf')

posicion_menor = 0

for i in range(M):

producto = producto_fila(matriz[i])

if producto > mayor_producto:

mayor_producto = producto

posicion_mayor = i

if producto < menor_producto:

menor_producto = producto

posicion_menor = i

print(posicion_mayor)

print(posicion_menor)

EJERCICIO 7

productos = {}

N = int(input())

for _ in range(N):

linea = input().split(":")

nombre = linea[0]

precio = float(linea[1])

productos[nombre] = precio
M = int(input())

total_compra = 0

for _ in range(M):

linea = input().split()

nombre_producto = linea[0]

cantidad = int(linea[1])

if nombre_producto in productos:

precio_unitario = productos[nombre_producto]

total_compra += precio_unitario * cantidad

if total_compra > 100000:

total_compra *= 0.7

print(total_compra)

EJERCICO 8

def crear_diccionario(n):

diccionario = {}

for _ in range(n):

palabra, traduccion = input().split(":")

diccionario[palabra] = traduccion.strip()

return diccionario

def traducir_oracion(oracion, diccionario):

palabras = oracion.split()

traduccion = " ".join([diccionario.get(palabra, palabra) for palabra in palabras])

return traduccion
n = int(input())

diccionario = crear_diccionario(n)

m = int(input())

for _ in range(m):

oracion = input()

traduccion = traducir_oracion(oracion, diccionario)

print(traduccion)

También podría gustarte