teslariu

aritmetica

Oct 25th, 2021
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # script que pide dos números y devuelve su cociente, suma, producto y
  5. # resta
  6.  
  7. def ingresar_numero(tipo):
  8.     while True:
  9.         try:
  10.             numero = float(input(f"Ingrese un número {tipo}: "))
  11.         except ValueError:
  12.             print("No ha ingresado un número")
  13.         else:  
  14.             if tipo=="b" and not numero:
  15.                 print("El nro b debe ser distinto de cero")
  16.             else:
  17.                 return numero
  18.  
  19. if __name__ == '__main__':
  20.     a = ingresar_numero("a")
  21.     b = ingresar_numero("b")
  22.  
  23.     print(f"La suma entre {a} y {b} es {a+b}")
  24.     print(f"La resta entre {a} y {b} es {a-b}")
  25.     print(f"El producto entre {a} y {b} es {a*b}")
  26.     print(f"El cociente entre {a} y {b} es {a/b}")
  27.  
Advertisement
Add Comment
Please, Sign In to add comment