Is_int help


#1

I don't know how to create an if statment to determine if a float ends with .0 can you give me a hint.

number = raw_input("enter a number:")

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

is_int(number)

#2

you could use abs


#3

Why doesn't this work for me?

def is_int(x):
    y = abs(x)
    if y / y == 0 :
        return True    
    else:
        return False

#4

for -2 the absolute value would be 2. so 2/2 equals one.

This doesn't work, you could check if the absolute value (abs) equals the value you get when casting to an integer (int)


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.