is_even(I know. It's early)



Oops, try again. is_even(48) returned False instead of the expected: True

def is_even(x):
    if x == x & 2:
        return True
        return False


Replaced the ampersand but still the same problem :confused:


Try using the modulo operator so you can check the remainder.


I replaced it with the modulator and came up with the same result...

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


is_even is a function, so will never equal to x % 2 or anything else.

To test for even parity,

if x % 2 == 0:

modulo operator, not modulator.

In division, there is the divisor which is also known as the modulus, and there is the dividend which is the number being divided, the quotient which is the result, in general, but in this case, the quotient is an integer, and the remainder is the modulo.


Check to see if the remainder is equal to zero.

For example

If x % 10 == 0
Then x is divisible by 10


So, by setting equality to 0 it can operate? I'm just trying to understand.


When the remainder is zero, that means the number is evenly divisible by the modulus.

x % 2 == 0

This means the number is even.

x % 2 != 0

means the number is odd.

This applies to divisibility across the board.

x % 3 == 0

means x is evenly divisible by 3 (a multiple of 3).

x % 5 == 0

means x is a multiple of 5, and so on.

2 ) 15 | 7
  - 14

The remainder, 1 is the modulo.


That's EXTREMELY helpful. Thank you.


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