Advertisement
teslariu

raise1

Sep 22nd, 2022
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Función que lanza su propia excepción
  5.  
  6. def sumar(a,b):
  7.     """Función que toma dos números como parámetros
  8.    y devuelve su suma. Si los parámetros no son numéricos
  9.    devuelve una excepción TypeError"""
  10.     if not isinstance(a,(int,float)) or not isinstance(b,(int,float)):
  11.         raise TypeError("Se requieren dos números")
  12.     return a+b
  13.    
  14. print(sumar(4,5))
  15. print(sumar("Hola","Chau"))
  16. print(sumar([1,2,3],[4,5,6]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement