teslariu

funciones propias

Jun 27th, 2023 (edited)
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Script que convierte temp de ºF a ºC y viceversa
  5. """
  6. def menu():
  7.     """
  8.    Función que imprime un menú de opciones
  9.    """
  10.     return"""
  11.    Conversión de temperatura
  12.    -------------------------
  13.    1. ºC a ºF
  14.    2. ºF a ºC
  15.    3. Salir
  16.    """
  17.    
  18. def borrar_pantalla():  
  19.     """Función que borra la pantalla"""  
  20.     import os
  21.     if os.name == "posix":
  22.         os.system("clear")
  23.     else:
  24.         os.system("cls")
  25.  
  26.  
  27. def ingresar_valor():
  28.     """Función que valida el ingreso de un nro racional"""
  29.     while True:
  30.         try:
  31.             temp = float(input("Ingrese la temperatura: "))
  32.         except ValueError:
  33.             print("Error: debe ingresar un número")
  34.         else:
  35.             return temp
  36.            
  37. if __name__ == '__main__':
  38.     import time
  39.    
  40.     while True:
  41.         borrar_pantalla()
  42.         print(menu())
  43.    
  44.         opcion = input("Seleccione una opcion: ")
  45.    
  46.         if opcion == "1":
  47.             temp = ingresar_valor()
  48.             print(f"Temperatura: {temp * 1.8 + 32:.1f}ºF")
  49.             time.sleep(3)
  50.        
  51.         elif opcion == "2":
  52.             temp = ingresar_valor()
  53.             print(f"Temperatura: {(temp - 32) / 1.8:.1f}ºF")
  54.             time.sleep(3)
  55.        
  56.         elif opcion == "3":
  57.             print("Hasta luego...")
  58.             break
  59.        
  60.         else:
  61.             print("Opción incorrecta...")
  62.             aux = input("Presione cualquier tecla para continuar...")
Advertisement
Add Comment
Please, Sign In to add comment