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