Advertisement
teslariu

menu while true

Apr 24th, 2023
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """
  5. Ejemplo de una plantilla de menu con WHILE TRUE
  6. Script que convierte temp de ºC a ºF y viceversa
  7. """
  8. import os    #Importamos el modulo os
  9. import time
  10.  
  11. while True:
  12.     print("""
  13.    Conversor de temperaturas
  14.    =========================
  15.    Menu de opciones
  16.    ----------------
  17.    1. ºC -> ºF
  18.    2. ºF -> ºC
  19.    3. Salir
  20.    ----------------
  21.    """)
  22.     opcion = input("Seleccione una opcion: ")
  23.  
  24.     if opcion == "1":
  25.         temp = float(input("Ingrese la temperatura: "))
  26.         print(f"{temp:.1f}ºC equivalen a {temp*1.8 + 32:.1f}ºF")
  27.    
  28.     elif opcion == "2":
  29.         temp = float(input("Ingrese la temperatura: "))
  30.         print(f"{temp:.1f}ºF equivalen a {(temp - 32) / 1.8:.1f}ºC")
  31.    
  32.     elif opcion == "3":
  33.         print("Gracias por usar este script")
  34.         break
  35.    
  36.     else:
  37.         print("Opción incorrecta")
  38.    
  39.     time.sleep(5)  # espero 5 segundos antes de borrar la pantalla
  40.    
  41.     # limpiar la pantalla
  42.     # Unix/Linux/MacOS/BSD
  43.     os.system("clear")
  44.     # DOS/Windows
  45.     os.system("cls")
  46.    
  47.    
  48.    
  49.    
  50.    
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement