DEV Community

Cover image for Python challenge_4
Mahmoud EL-kariouny
Mahmoud EL-kariouny

Posted on • Updated on

Python challenge_4

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
        return False

print(only_ints("tito", 2)) 
Enter fullscreen mode Exit fullscreen mode

Another solution

def only_ints(a, b):

    return type(a) == int and type(b) == int
Enter fullscreen mode Exit fullscreen mode

Add your solution in the comment :)

Top comments (1)

finebythen profile image
Finn Then

return isinstance(a, int) and isinstance(b, int)