Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- Script que convierte temp de ºF a ºC y viceversa
- """
- def menu():
- """
- Función que imprime un menú de opciones
- """
- return"""
- Conversión de temperatura
- -------------------------
- 1. ºC a ºF
- 2. ºF a ºC
- 3. Salir
- """
- def borrar_pantalla():
- """Función que borra la pantalla"""
- import os
- if os.name == "posix":
- os.system("clear")
- else:
- os.system("cls")
- def ingresar_valor():
- """Función que valida el ingreso de un nro racional"""
- while True:
- try:
- temp = float(input("Ingrese la temperatura: "))
- except ValueError:
- print("Error: debe ingresar un número")
- else:
- return temp
- if __name__ == '__main__':
- import time
- while True:
- borrar_pantalla()
- print(menu())
- opcion = input("Seleccione una opcion: ")
- if opcion == "1":
- temp = ingresar_valor()
- print(f"Temperatura: {temp * 1.8 + 32:.1f}ºF")
- time.sleep(3)
- elif opcion == "2":
- temp = ingresar_valor()
- print(f"Temperatura: {(temp - 32) / 1.8:.1f}ºF")
- time.sleep(3)
- elif opcion == "3":
- print("Hasta luego...")
- break
- else:
- print("Opción incorrecta...")
- aux = input("Presione cualquier tecla para continuar...")
Advertisement
Add Comment
Please, Sign In to add comment