teslariu

control de tipos

Nov 13th, 2021
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. def sumar(a,b):
  5.     """
  6.     Función que pide dos numeros y retorna la suma entre ellos
  7.     """
  8.     if not isinstance(a, (int,float)) or not isinstance(b,(int, float)):
  9.         raise TypeError("Se requieren dos números")
  10.     return a+b
  11.  
  12.  
  13.  
  14. a = "Hola"
  15. b = "Chau"
  16. print(sumar(a,b))
Advertisement
Add Comment
Please, Sign In to add comment