Advertisement
teslariu

aritm2

Nov 30th, 2021
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Script que pide dos numeros y devuelve su cociente
  5.  
  6. def ingresar_numero():
  7.     while True:
  8.         try:
  9.             n = float(input(f"Ingrese un número: "))
  10.         except ValueError:
  11.             print("No ha ingresado un número")
  12.         else:
  13.             return n
  14.    
  15. def suma(a,b):
  16.     return a + b
  17.    
  18. def producto(a,b):
  19.     return a*b
  20.  
  21. if __name__ ==  "__main__":
  22.     print("Script que calcula la suma o el producto de dos nros")
  23.  
  24.     while True:
  25.    
  26.         print("""
  27.         Opciones
  28.         1. Suma
  29.         2. Producto
  30.         3. Salir
  31.         """)
  32.         opcion = input("Seleccione una opción: ")
  33.    
  34.         if opcion == "1":
  35.             a = ingresar_numero()
  36.             b = ingresar_numero()
  37.             print(suma(a,b))
  38.        
  39.         elif opcion == "2":
  40.             a = ingresar_numero()
  41.             b = ingresar_numero()
  42.             print(producto(a,b))
  43.        
  44.         elif opcion == "3":
  45.             print("Adios")
  46.             break
  47.        
  48.         else:
  49.             print("Error, no existe la opción")
  50.        
  51.  
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement