15.3 is_int Can someone please review this code? It works but I need to know if something can be improved


#1


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/3

Can someone please review this code? It works but I need a confirmation that this is the best way to go about it without using any imports


def is_int(x):
    if type(x) == int:
        return True
    elif (x - int(x)) == 0:
        return True
    else:
        return False


3. is_int
#2

When testing and validating inputs we don't know what we're going to get. Using a definitive approach right out of the gate may not be the way to go. What if we assume the user is entering correct input, to the best of their knowledge. Then it is up to us to coerce that input into the data type we wish to continue with. This means assume the input looks like what we're after.

Given this premise, can you take another look at your code and refine it?

Can we rule out that it is a list? How about a dictionary? How about a function? Once we rule out those objects we're down to primitives, Boolean, Number, or String.

One thing we know for sure, a lot can be eliminated with, isnan(). Then we're down to separating float from integer. Once we know we have a number, an integer is not very far away.