is_int - this code should work, no?


#1
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

#2

My mistake, "7.0" is also considered as integer.


#3

:smile: 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.


#4

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 :smiley:


#5

Here mine that worked :smile:

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