Is_int problem!


I've already tried this codes but i keep getting this error:
Oops, try again. Your function fails on is_int(-2). It returns None when it should return True.
the codes:
def is_int(x):
if round(x)==x:
print True
print False
def is_int(x):
if type(x)==int:
print True
print False
def is_int(x):
if round(x)-x==0:
print True
print False

Replace this line with your code.


The operative word here is return.


How did you know that you should use round() ???


Ok here instead of using the round() function in your code try my code which is given below and check whether you get a go ahead as i got and also if u think mark it as a solution :smile:

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

for the explanation:
here we first calculate the value of temp by subtracting the integer part of x with original value of x (explicit type conversion as in code). Then if temp >0 it means there is a fractional part and hence the number is not an integer and return False OTHERWISE return True


thanks for your help buddy


Thank U:slight_smile:


Most Welcome Bro :smile:


You answer is really clever good job :wink:


There is only one problem. The instructions specifically state that we are not to use the int() function in our solution. If clever means disobey the instructions, then I guess it can be called a good job. Recommend find another solution that does not use, int().