Advertisement
teslariu

fun

Jul 10th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Script que recibe como paràmetro una temperatura en ºF o ºC y la convierte
  6. a la otra escala:
  7. NOTAS:
  8. 1) Las fórmulas de conversión son:
  9.  F = 9*C/5 + 32,      C = (F-32) * 5/9
  10.  
  11. 2) Use funciones
  12. 3) Escribir el programa de manera que el usuario pueda ejecutar todas las
  13. conversiones que desee (el script debe preguntarle si desea seguir o no)
  14. 4) 10ºC = 50ºF
  15.  
  16. """
  17. def mostrar_menu():
  18.     print("""\nMenú de opciones:
  19.    1. Conversión de ºC a ºF
  20.    2. Conversión de ºF a ºC
  21.    3. Salir
  22.    """)
  23.  
  24. def ingresar_temperatura():
  25.     t = float(input("Ingrese la temperatura: "))
  26.     return t
  27.  
  28. def convertir_a_farenheit(t):
  29.     return 9*t/5 + 32
  30.    
  31. def convertir_a_celsius(t):
  32.     return (t-32) * 5/9
  33.    
  34. def imprimir_temperatura(valor,escala):
  35.     print("La temperatura es {:.1f}º{}".format(valor,escala))
  36.    
  37. def despedir():
  38.     print("Gracias por utilizar este programa...")
  39.    
  40. def imprimir_error():
  41.     print("Opción incorrecta...")
  42.    
  43.    
  44.  
  45. print("Programa de conversión de temperaturas")
  46. print("--------------------------------------")
  47.  
  48. while True:
  49.    
  50.     mostrar_menu()
  51.    
  52.     opcion = input("Seleccione su opción: ")
  53.    
  54.     if opcion == "1":
  55.         temperatura = ingresar_temperatura()
  56.         valor = convertir_a_farenheit(temperatura)
  57.         imprimir_temperatura(valor,"F")
  58.    
  59.     elif opcion == "2":
  60.         temperatura = ingresar_temperatura()
  61.         valor = convertir_a_celsius(temperatura)
  62.         imprimir_temperatura(valor,"C")
  63.            
  64.     elif opcion == "3":
  65.         despedir()
  66.         break
  67.        
  68.     else:
  69.         imprimir_error()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement