Advertisement
teslariu

excepciones

Jan 15th, 2022
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. cociente = int(input("Ingrese un divisor: "))
  5.  
  6. try:
  7.     a = 25 / cociente
  8. except ZeroDivisionError:
  9.     print("no se puede dividir por cero")
  10. else:
  11.     print(f"Cociente: {a}")
  12. finally:
  13.     print("Adiós")
  14.  
  15. # forma no recomendable 1
  16. cociente = int(input("Ingrese un divisor: "))
  17. try:
  18.     a = 25 / cociente
  19. except:
  20.     print("Error")
  21. else:
  22.     print(f"Cociente: {a}")
  23. finally:
  24.     print("Adiós")
  25.    
  26. # forma no recomendable 2
  27. cociente = int(input("Ingrese un divisor: "))
  28. try:
  29.     a = 25 / cociente
  30. except Exception:
  31.     print("Error")
  32. else:
  33.     print(f"Cociente: {a}")
  34. finally:
  35.     print("Adiós")
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement