#1

Hi I need your help! It doesn't work.

var is_even = function(x){
if(x % 2 === 0){
return True;
}else{
return False;
};
};

#2

This looks like JavaScript, not Python, except for the True False.

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

There are resemblences, but differences, too.

#3

Hello, I have a question. I don't understand why you are using "x % 2 == 0" first of all whats the differens between "%" and "/" and the second why should it be equal (==) to "0".

Thanx

#4

The `modulo` operator is used to extract the remainder of a division. Usually it is integer division, a / b where both a and b are integers. The remainder is also an integer. The `%` operator is sometimes referred to as the `remainder operator`.

``````      15
_____
2  ) 31
-30
____
1``````

so 31 % 2 is 1

The modulo of any odd number divided by 2 is always 1. When there is no remainder, we know that the parity is `even`. That is why we look for a 0 remainder.

``if x % 2 == 0  =>  then x is even``

#5

Aha that make a lot of sense. Thanx alot