Is_int - why my code works


Yo, I've done this example. But I have abit headache and I have problem to understand why my code works. Here is my code:

def is_int(x):
    if x<0:
    if x//1!=x:
        return False
        return True


Hi, @acrodan ,

This part of your function is not technically an error, but it does not contrubite anything to the solution, so it should be removed ...

    if x<0:

This if header performs the essential task ...

if x//1!=x:

x//1 performs int division, which returns a value that is equivalent to the value x with any fractional parts removed. If the result of that operation is equivalent to the value of x, then the value of x is equivalent to an int, even if x is a float.


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