Python Python Basics (2015) Number Game App Even or Odd

victor escarcega
victor escarcega
5,439 Points

I'm having a hard time understanding the instructions.

So how does this one work?

even.py

2 Answers

Aayush Mitra
Aayush Mitra
24,362 Points

Hi Victor!

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.

def even_odd(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.

Thanks! :)

victor escarcega
victor escarcega
5,439 Points

Thank you very much for your help! I dont recall the video going over the % sign but ill have to look into it.

Much appreciated!