Advertisement
teslariu

ejemplo funciones

Feb 4th, 2023
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Script que convierte temperaturas no negativas de ºC a ºF y viceversa
  5. """
  6. def menu():
  7.     return """
  8.    1. ºC -> ºF
  9.    2. ºF -> ºC
  10.    3. Salir
  11.    """
  12. def ingresar():
  13.     while True:
  14.         temp = input("Ingrese la temperatura: ")
  15.         if temp.isdecimal():
  16.             return int(temp)
  17.         else:
  18.             print("Debe ingresar un entero no negativo")
  19.        
  20.  
  21. def farenheit(temp):
  22.     return f"{temp * 1.8 + 32}ºF"
  23.    
  24. def celsius(temp):
  25.     return f"{(temp - 32) / 1.8:.1f}ºC"
  26.  
  27.  
  28.  
  29. print("Conversor de temperaturas")
  30. while True:
  31.     print(menu())
  32.    
  33.     opcion = input("Seleccione una opcion: ")
  34.     if opcion == "1":
  35.         temp = ingresar()
  36.         print(farenheit(temp))
  37.        
  38.     elif opcion == "2":
  39.         temp = ingresar()
  40.         print(celsius(temp))
  41.        
  42.     elif opcion == "3":
  43.         print("Gracias por usar este programa")
  44.         break
  45.        
  46.     else:
  47.         print("Opción incorrecta")
  48.        
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement