Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Script que permite convertir temperaturas de ºF a ºC y viceversa
- # En esta versión vamos a incluir funciones y manejo de excepciones
- def menu():
- return"""
- Menu de opciones
- ----------------
- 1. ºC --> ºF
- 2. ºF --> ºC
- 3. Salir
- ---------------
- """
- def ingresar_temperatura():
- while True:
- try:
- temp = float(input("Ingrese la temperatura: "))
- except ValueError:
- print("Error, debe ingresar un número")
- else:
- return temp
- def pasar_a_C(temp):
- temp = (temp - 32) / 1.8
- return f"La temperatura es {temp:.1f}ºC"
- def pasar_a_F(temp):
- temp = (temp * 1.8) + 32
- return f"La temperatura es {temp:.1f}ºF"
- print("Conversor de temperaturas")
- while True:
- print(menu())
- opcion = input("Seleccione su opción: ")
- if opcion == "1":
- temp = ingresar_temperatura()
- print(pasar_a_F(temp))
- elif opcion == "2":
- temp = ingresar_temperatura()
- print(pasar_a_C(temp))
- elif opcion == "3":
- print("Hasta luego...")
- break
- else:
- print("Opción incorrecta...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement