-
Notifications
You must be signed in to change notification settings - Fork 901
Description
Def mostrar_menu():
Print(“\n=== MENÚ PRINCIPAL ===”)
Print(“1. Problema 1: Mostrar asignaturas”)
Print(“2. Problema 2: Datos personales en diccionario”)
Print(“3. Problema 3: Calcular total con IVA”)
Print(“4. Problema 4: Tabla de multiplicar en archivo”)
Print(“5. Salir”)
Ejercicio 1
Def problema1():
Print(“\n--- Problema 1 ---“)
Asignaturas = [“Matemáticas”, “Física”, “Química”, “Historia”, “Lengua”]
Print(“Las asignaturas del curso son:”)
For asignatura in asignaturas:
Print(asignatura)
Ejercicio 2
Def problema2():
Print(“\n--- Problema 2 ---“)
Nombre = input(“Ingrese su nombre: “)
Edad = input(“Ingrese su edad: “)
Direccion = input(“Ingrese su dirección: “)
Telefono = input(“Ingrese su número de teléfono: “)
Datos = {
“nombre”: nombre,
“edad”: edad,
“dirección”: direccion,
“teléfono”: telefono
}
Print(f”{datos[‘nombre’]} tiene {datos[‘edad’]} años, vive en {datos[‘dirección’]} y su número de teléfono es {datos[‘teléfono’]}.”)
Ejercicio 3
Def problema3():
Print(“\n--- Problema 3 ---“)
Try:
Cantidad = float(input(“Ingrese la cantidad sin IVA: “))
Porcentaje = input(“Ingrese el porcentaje de IVA (deje vacío para 21%): “)
If porcentaje == “”:
Porcentaje = 21
Else:
Porcentaje = float(porcentaje)
Total = cantidad * (1 + porcentaje / 100)
Print(f”Total con IVA ({porcentaje}%): {total:.2f}”)
Except ValueError:
Print(“Por favor ingrese valores numéricos válidos.”)
Ejercicio 4
Def problema4():
Print(“\n--- Problema 4 ---“)
Try:
Numero = int(input(“Ingrese un número entre 1 y 10: “))
If 1 <= numero <= 10:
Nombre_archivo = f”tabla-{numero}.txt”
With open(nombre_archivo, “w”) as archivo:
For I in range(1, 11):
Archivo.write(f”{numero} x {i} = {numero * i}\n”)
Print(f”Tabla del {numero} guardada en el archivo ‘{nombre_archivo}’.”)
Else:
Print(“El número debe estar entre 1 y 10.”)
Except ValueError:
Print(“Debe ingresar un número entero válido.”)
Bucle principal
While True:
Mostrar_menu()
Eleccion = input(“Elige una opción: “)
If eleccion == “1”:
Problema1()
Elif eleccion == “2”:
Problema2()
Elif eleccion == “3”:
Problema3()
Elif eleccion == “4”:
Problema4()
Elif eleccion == “5”:
Print(“Saliendo del programa…”)
Break
Else:
Print(“Opción no válida. Intente de nuevo.”)