Explore

Python Programs

Python Program To Check Even Or Odd Numbers

Python Program To Check Even Or Odd Numbers

Today in this python tutorial I will show you how to create a python program to check even or odd numbers. This python program is very simple and easy to do. You just need to read this tutorial guide till the end.

Now let’s see how this program will work. Since you are reading this python guide you should be knowing about even and odd numbers if you don’t know you can see from the below example:

  • Even numbers: 2, 4, 6, 8, … all numbers which are divisible by 2.
  • Odd numbers: 1, 3, 5, 7, … all numbers which are not divisible by 2.

Our goal in this python program is to ask the user to enter a number then we will check the number using the modulus operator (%) in python.

The modulus operator returns the remainder of a number so we can determine if the number is even or odd with the remainder of the number.

If the remainder of a number is 0 when divided by 2 then the number will be called an even number. If not then it will be called an odd number. I hope you understood so now let’s see this in code.


num = int(input('Enter a number: '))

if (num % 2) == 0:
    print(f'number {num} is Even')
else:
    print(f'number {num} is Odd')

You can run the above code in a online python compiler or on your computer and you will be asked to enter a number then it will print if the number is even or odd below is the example of the output.


> Enter a number: 10
>> number 10 is Even

Note that we need to divide the number by 2 (because even numbers are divisible by 2 and odd numbers are not) and check if the remainder is 0 as you can see that’s what we did in the above code.

So this was the python program to find if a number is even or odd. I hope you found it helpful and solved your problem. We have tons of python tutorials you can check here – View Pythondex Guides.

Want to get the latest updates from our blog then do join our Telegram channel we upload exclusive python guides and tutorials.

Thanks for reading, have a nice day 🙂