Advertisement
teslariu

template con menu while true

May 6th, 2023
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Programa que convierte una temp de ºC a ºF y viceversa
  5. # Template o plantilla while True con menu y funcion borrar pantalla
  6.  
  7. def borrarPantalla():
  8.     import os
  9.     if os.name == "posix":
  10.         os.system ("clear")
  11.     else:
  12.         os.system ("cls")
  13.  
  14. titulo = "Programa de conversión de temperaturas"
  15.  
  16. menu_de_opciones = """
  17.    Menu de opciones:
  18.    -----------------
  19.    1. ºC a ºF
  20.    2. ºF a ºC
  21.    3. Salir
  22.    -----------------
  23. """
  24.  
  25.  
  26.  
  27. while True:
  28.     borrarPantalla()
  29.    
  30.     print(titulo)
  31.     print(menu_de_opciones)
  32.     opcion = input("Ingrese una opción: ")
  33.    
  34.     if opcion == "1":
  35.         temp = float(input("Ingrese una temperatura: "))
  36.         print(f"{temp}ºC equivalen a {temp * 1.8 + 32}ºF")
  37.        
  38.        
  39.     elif opcion == "2":
  40.         temp = float(input("Ingrese una temperatura: "))
  41.         print(f"{temp}ºF equivalen a {(temp - 32) / 1.8:.1f}ºC")
  42.        
  43.     elif opcion == "3":
  44.         print("Gracias por utilizar este programa...")
  45.         break
  46.        
  47.     else:
  48.         print("Opción incorrecta")
  49.        
  50.     input("\nPresione cualquier tecla para continuar")
  51.    
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement