Type check
level of challenge = 2/10
Write a function named only_ints that takes two parameters.
Your function should return True if both parameters are integers, and False otherwise.
For example, calling only_ints(1, 2) should return True, while calling only_ints("a", 1) should return False.
My solution
def only_ints(num_1, num_2):
if type(num_1) == int and type(num_2) == int:
return True
else:
return False
print(only_ints("tito", 2))
Another solution
def only_ints(a, b):
return type(a) == int and type(b) == int
Add your solution in the comment :)
Top comments (1)
return isinstance(a, int) and isinstance(b, int)