Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #raise lanza excepciones KeyError, ValueError, NameError, TypeError
- def suma(a,b):
- return a+b
- def resta(a,b):
- return a-b
- def multiplicar(a,b):
- return a*b
- def dividir(a,b):
- if b:
- return a/b
- else:
- raise ZeroDivisionError
- def cargar_datos():
- while True:
- try:
- a = float(input("Ingrese un nro: "))
- return a
- except Exception:
- print("Debe ingresar un nro")
- while True:
- a = cargar_datos()
- b = cargar_datos()
- try:
- print("a+b:",suma(a,b))
- print("a-b:",resta(a,b))
- print("a*b:",multiplicar(a,b))
- print("a/b:",dividir(a,b))
- except ZeroDivisionError:
- print("No se puede dividir por cero")
- finally:
- print("----------------------------------------------")
- opcion = input("Presione cualquier tecla para continuar ('x' para salir) :")
- if opcion.casefold() == "x":
- print("Adios...")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement