Help Needed Is_int


#1



Exercise Practice Makes Perfect #3


My code errors saying that my function is_int(-2) fails. Returns False when it should return True.


I thought my first if statement took care of this since -2 is an integer


def is_int(x):
    if x == int:
        return True
    elif x == float:
        return True
    elif abs(x) == str(x) + "." + "0":
        return True
    else:
        return False


#2

here:

    elif x == float:
        return True

are you sure you want to return True for all floats? I don't think so

no, int doesn't see negative values (and zero) as integers. integers are positive numbers. You need more help, or do you think you can go further now i pointed to your mistake?


#3

I believe I will be able to figure it out from here. Thanks for your assistance.


#4

okay, good luck! the help line stays open if you can't figure it out :wink:


#6

Look up python floor division. That should clear things up. Hope it helps!


#8

>>> x = 3.14
>>> x == float
False
>>> type(x) == float
True
>>>

However, we are told not to refer to a built-in method. The suggestion above is more on target, as is the modulo example given in the Hint.


#11