Python Program to Check Whether a Number is Even or Odd

In this post, I am going make a Python’s program which will check whether a number is even or odd. But before making program, first you need to understand  modulus operator %.

The above code defined a variable num which refers to 4, and variable r refers remainder when 2 divides num, so r will refer 0.


The above code defined a variable num which refers to 5, and variable r refers remainder when 2 divides num, so r will refer 1.

Both concepts we will use to check whether a program is odd or even.


num=int(input("Enter a Number")
if num%2==0:
       print("Number is Even")
else:
       print("Number is Odd)"

print(r)

Consider the above program, if you take 4 as input num%2==0 will result as True and output would be “Number is Even”. If you take 5 as input num%2==0 will result as False and control will get transferred to else and output would be “Number is Odd”.

Leave a Comment

Your email address will not be published. Required fields are marked *

©Postnetwork-All rights reserved.