Advertisement
teslariu

lanzar excepciones

Jan 15th, 2022
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # lanzar excepciones
  5. def sumar(a,b):
  6.     """Funcion que recibe dos numeros y devuelve su suma"""
  7.     if not isinstance(a, (int, float)) or not isinstance(b, (int,float)):
  8.         raise TypeError("Se requieren dos numeros")
  9.     return a + b
  10.  
  11.  
  12. print(sumar(2,5.8))
  13. print(sumar([1,2], [True,"Chau"]))
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement