2. is_even



I keep getting an error message that says odd numbers are returning as True, but I don't understand how my code allows for them to return as True. Am I missing something?

def is_even(x):
    if x % 2:
        return True
        return False


I figured it out! Never mind!


Hi designwhiz08765,
please what do I have to change in this my code:
def is_int(x):
if x - round(x) > 0:
return True
return False


You can try using the modulus function instead.

n % a == x #n is the dividend, a is the divisor, and x is the remainder

As an integer can be defined as any number that produces a remainder of 0 when divided by 1.

3.5 % 1 == 5 #Hence, it is not an integer
3 % 1 == 0 #Hence, it is an intenger

But if you want to use round(), I suggest you import math as round is in the math module.
However, let's say your input is 2 (an integer), and it goes through x-round(x), it would be equal to 0.
But, your code states that it has to be greater than 0 so 2 is not an integer according to your code.