victor escarcega5,439 Points
I'm having a hard time understanding the instructions.
So how does this one work?
Aayush Mitra24,362 Points
This one can get tricky, so let me walk you through it.
So we know that an even number is always divisible by 2.
What we need to do is to check whether the number that the user gave is divisible by 2. If it is, it is even. If it is not, it is odd.
It asks us to define a function even_odd and give it one argument. I will call it num.
No look at the description I gave earlier. I used the key word "if" a lot. We will need to use an if statement.
First we check whether num is divisible or not. If it is, return true. We can check this using the modulo or % sign.
if num % 2 == 0: return True
If you don't understand the modulo sign, I suggest going back to the video a few times.
If it is not divisible by 2, then return False. We do not need to type another condition. We can just use else because the number has to be either even or odd. So if it is not even, it has to be odd.
else: return False
Here is all the code:
def even_odd(num): if num % 2 == 0: return True else: return False
I hope this helps!
If you have any more questions please let me know.