teslariu

conver_func

Sep 10th, 2021 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Programa que pide una temperatura y la convierte de ºC a ºF o viceversa
  5.  
  6. def inicio():
  7.     print("Programa de conversión de temperaturas")
  8.     print("=========================================")
  9.  
  10. def menu():
  11.     print("\n********** Menu de opciones ************")
  12.     print("\t1. Conversión de ºC a ºF")
  13.     print("\t2. Conversión de ºF a ºC")
  14.     print("\t3. Salir")
  15.    
  16. def celsius_a_farenheit():
  17.     temperatura = float(input("Ingrese la temperatura (en ºC): "))
  18.     temperatura = temperatura * 1.8 + 32
  19.     return temperatura
  20.    
  21. def farenheit_a_celsius():
  22.     temperatura = float(input("Ingrese la temperatura (en ºF): "))
  23.     temperatura = (temperatura - 32) / 1.8
  24.     return temperatura 
  25.    
  26. #############################################
  27.  
  28. inicio()
  29.  
  30. while True:
  31.    
  32.     menu()
  33.  
  34.     opcion = input("Seleccione una opción: ")
  35.  
  36.     if opcion == "1":
  37.         print(f"La temperatura convertida es {celsius_a_farenheit()}ºF")
  38.    
  39.     elif opcion == "2":
  40.         print(f"La temperatura convertida es {farenheit_a_celsius()}ºC")
  41.        
  42.     elif opcion == "3":
  43.         print("Gracias por utilizar este programa...")
  44.         break
  45.        
  46.     else:
  47.         print("Opción incorrecta")
  48.  
Add Comment
Please, Sign In to add comment