teslariu

try

Sep 11th, 2021
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 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 ingresar_temperatura():
  17.     while True:
  18.         try:   
  19.             temp = float(input("Ingrese la temperatura: "))
  20.         except ValueError:
  21.             print("Error, debe ingresar un nro")
  22.         else:
  23.             return temp
  24.  
  25.  
  26. def celsius_a_farenheit(temp):
  27.     return temp * 1.8 + 32
  28.    
  29.  
  30. def farenheit_a_celsius(temp):
  31.     return (temp - 32) / 1.8
  32.    
  33.    
  34. #############################################
  35.  
  36. inicio()
  37.  
  38. while True:
  39.    
  40.     menu()
  41.  
  42.     opcion = input("Seleccione una opción: ")
  43.  
  44.     if opcion == "1":
  45.         temp = ingresar_temperatura()
  46.         print("La temperatura convertida es {:.1f}ºF".format(celsius_a_farenheit(temp)))
  47.    
  48.     elif opcion == "2":
  49.         temp = ingresar_temperatura()
  50.         print("La temperatura convertida es {:.1f}ºC".format(farenheit_a_celsius(temp)))
  51.        
  52.     elif opcion == "3":
  53.         print("Gracias por utilizar este programa...")
  54.         break
  55.        
  56.     else:
  57.         print("Opción incorrecta")
  58.  
Advertisement
Add Comment
Please, Sign In to add comment