I don't know what I'm supposed to have as my code but I'm not good at coding :(.

Is this a GLITCH? or just me making an ERROR?

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


Thanks is ADVANCE :smiley:


when x % 2 gives 0, (when x is even)
0 is a Falsy value ,It means 0 will be seen as False

so if condition sees a "False" value and runs else part!

One thing to understand..

if (0):

when you give 0 as value of if condition.
0 is actually False and when if sees it as False ,It will transfer the execution to else part.

You need to switch the returning Boolean values?


So I should make my code
def is_even(x):
if x % 2:
return False
return True



Weird, Why did that work?


Why did it not work? (your first code)

Okay lets see..

when you do this..

0 == False

It will return True.
It means that 0 is equivalent/equal to False.

So in your program..when it gets an even number then x % 2 produces 0
As 0 is equivalent to False then it does not executes the if block (we know when condition turns out to be False if transfers the execution to else block)
and thus your else block executes the code and returns False.


But I tried this with This code:
def is_even(x):
if x / 2:
return False
return True

And it didn't work... why?


Can you tell me if the last issue solved ?


Last Issue? what do ya mean?


This exercise?The one's code you posted?


I don't get it
:frowning: :frowning:


I have the code for this exercise posted up top...


I was asking if your program ran and have you understood what I posted in this post?


Post withdrawn :smiley:


No, I have not understood... I don't get it :frowning:


I'M AN IDIOT SORRY :frowning: I just figured it out... Thanks for yer help :smiley:


Okay, You last code...

we're going to see why It will not work..

When you divide a number.

say if X is divided by Y,

You get two things.

X / Y -- > Quotient say Q


X % Y --> Remainder say R

modulo - % - is used to find this R,It means It gives you remainder not quotient.
division - / - operator gives you Quotient.


13 / 5 -- > gives you Quotient 2.
13 % 5 --> gives you Remainder 3.

Remainder makes sure if a number is divisible or not by some number.
so we use % operator,we can't use/ for divisibility check.


What is Quotient?


Thanks for that now I understand (other than Quotient)