def is_int(x): flag = 0 x = str(x) #print len(x) for i in range(0, len(x)): if x[i] == ".": flag += 1 break #print flag if flag == 1: return False else: return True
My mistake, "7.0" is also considered as integer.
nice function, but you making it a bit too difficult for yourself. I think they intended you to use the type() function, which makes it quite a bit easier.
Yes actually there are various ways to make it easier, tried this code, worked
def is_int(x): if x % 1 == 0: return True else: return False
so simple, thanks though
Here mine that worked
def is_int(x): if x - int(x) == 0: return True else: return False