Is_int


#1

import math

def is_int(x):
    if type(x) == int or type(-x) == int or math.trunc(x) == int:
        return True
    else:
        return False
        
print math.ceil(7.0)
print math.floor(7.0)
print math.trunc(7.0)
print type(math.trunc(7.0))

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

BUT print type(math.trunc(7.0)) returns int.
What's wrong?


#2

I got. I forgot type() on math.trunc(x) == int


#3

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