teslariu

funciones 2

Nov 26th, 2022
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4.  
  5. # Hacer una función que transforme una distancia expresada en mts a kms
  6.  
  7. """
  8. def pasar_a_kms(dist):
  9.    pass
  10.    
  11. distancia = float(input("Ingrese una distancia en mts: "))
  12.  
  13. def pasar_a_kms(dist):
  14.    return dist/1000
  15.  
  16.  
  17. distancia = float(input("indique la cantidad en metros: "))
  18. print(pasar_a_kms(distancia))
  19.  
  20. """
  21.  
  22.  
  23. # TEMPLATE MENU CON WHILE TRUE
  24.  
  25. # Script que convierte valores enteros de temperaturas de ºC a ºF y viceversa
  26.  
  27. def titulo():
  28.     return """
  29.    Conversor de temperaturas
  30.    =========================
  31.    """
  32.  
  33. def menu():
  34.     return """
  35.    Menu de opciones
  36.    ----------------
  37.    1. ºC --> ºF
  38.    2. ºF --> ºC
  39.    3. Salir
  40.    """
  41.    
  42. def ingresar():
  43.     while True:
  44.         temp = input("Ingrese la temperatura: ")
  45.         if temp.isdecimal():
  46.             return int(temp)
  47.         else:
  48.             print("Error: debe ingresar un nro entero mayor o igual a cero")
  49.            
  50.            
  51. def pasar_a_ºF(t):
  52.     return f"Temperatura: {t * 1.8 + 32:.1f}ºF"
  53.    
  54.  
  55. def pasar_a_ºC(t):
  56.     return f"Temperatura: {(temp - 32 ) / 1.8:.1f}ºC"
  57.    
  58.  
  59. ################################################################
  60.  
  61. print(titulo())
  62.  
  63. while True:
  64.    
  65.     print(menu())
  66.     opcion = input("Seleccione una opción: ")
  67.    
  68.     if opcion == "1":
  69.         temp = ingresar()
  70.         print(pasar_a_ºF(temp))
  71.        
  72.                
  73.     elif opcion == "2":
  74.         temp = ingresar()
  75.         print(pasar_a_ºC(temp))
  76.        
  77.                
  78.     elif opcion == "3":
  79.         print("Gracias por usar este programa...")
  80.         break
  81.        
  82.     else:
  83.         print("Opción incorrecta")
  84.  
  85.  
  86.  
Advertisement
Add Comment
Please, Sign In to add comment