Advertisement
teslariu

lanzar excepciones

Jan 15th, 2022
729
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement