Advertisement
teslariu

template While True

Aug 10th, 2023
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4.  
  5. ### Ejemplo de template While True para resolver ejercicios
  6. def validar(escala):
  7.     while True:
  8.         try:
  9.             n = float(input(f"Ingrese la temperatura (en {escala}): "))
  10.         except ValueError:
  11.             print("Error, debe ingresar una temperatura válida")
  12.         else:
  13.             return n
  14.  
  15.  
  16. def menu():
  17.     print("""
  18.    Menu de opciones
  19.    ----------------
  20.    1. ºC a ºF
  21.    2. Opcion 2
  22.    3. Opcion 3
  23.    4. Salir
  24.    """)
  25.     opcion = input("Ingrese una opción: ")
  26.     return opcion
  27.    
  28.    
  29. while True:
  30.     opcion = menu()
  31.    
  32.     if opcion == "1":
  33.         temp = validar("ºC")
  34.        
  35.        
  36.     elif opcion == "2":
  37.         pass
  38.    
  39.     elif opcion == "3":
  40.         pass
  41.        
  42.     elif opcion == "4":
  43.         print("Gracias por utilizar este programa...")
  44.         break
  45.        
  46.     else:
  47.         print("Opción incorrecta...")
  48.    
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement