Advertisement
teslariu

aritmetic

Jun 27th, 2022
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Módulo que implementa  una calculadora que pide dos nros y devuelve
  6. el resultado de las 4 operaciones básicos entre ellos
  7. """
  8.  
  9. def ingresar_numero():
  10.     while True:
  11.         try:
  12.             numero = float(input("Ingrese un número: "))
  13.         except ValueError:
  14.             print("Error, debe ingresar un número")
  15.         else:
  16.             return numero
  17.            
  18. def suma(a,b):
  19.     return a + b
  20.    
  21. def resta(a,b):
  22.     return a - b
  23.    
  24. def producto(a,b):
  25.     return a * b
  26.    
  27. def cociente(a,b):
  28.     if b != 0:
  29.         return a / b
  30.     else:
  31.         raise ZeroDivisionError
  32.  
  33. if __name__ == "__main__":
  34.     a = ingresar_numero()
  35.     b = ingresar_numero()        
  36.     print(f"{a} + {b} = {a+b}")
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement