Is_int


#1



I must be having a bad day because this is the second one in a row I can't figure out.


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/3?curriculum_id=4f89dab3d788890003000096


Oops, try again. Your function fails on is_int(-2). It returns False when it should return True.


It's supposed to check to see if a number is an integer and include negatives and decimal zeros.


def is_int(x):
    
    if x == int:
        return True
        
    else:
        return False


#2

x will not equal to int, but its type may.

if type(x) == int:

However, I don't believe we are expected to use the built-in to match the type. Can you think of another way?


#3

That does help, but you're right. Using the type and int is not enough. I somehow need to include number that have a decimal followed by 0. Like 7.0. Not certain how to explain that in code form. I feel like they gave me a hint by saying "If the difference between a number and that same number rounded down is greater than zero, what does that say about that particular number?". Again, I don't know how I'm supposed to represent this in code.


#4

Using the round() function,

return round(n) == n

Using a modulo operation,

return not n % 1

Both of these should let a float such as 7.0 pass.


#5

Thanks! That's exactly what I needed. It worked perfectly.


#8