Python Program To Check If a Number is Odd or Even

26

In this simple Python program, you will learn to check if a number is odd or even. Before moving ahead, please ensure that you understand the basic concepts of Python programming, such as:

  • Variables
  • Python operators
  • If-else statements

In case you have just started your Python journey, then here are some resources that you should check out:

Here are some similar Python program examples you should check out:

Python Program To Check If a Number is Odd or Even

Let’s now see how to check if a number is odd or even using Python code.

It is as simple as ABC. We will take input from the user and then check if the number is divisible by 2 or not. If the number is divisible by 2, it is an even number; otherwise, the given number is odd.

We will check the divisibility using the modulo operator (%) and use if-else Python statements to print if the number is odd or even.

Here’s the code for the same.

#Python program to check if a number is odd or even

#Input number from user 
number = int(input("Enter a number to check odd or even \n"))

#Checking if the nunmber is divisible by 2 or not

#If the number is divisible by 2 then it is an even number
if (number % 2) == 0:
    print("Number is even")
#If the number is not divisble by 2 then it is an odd number    
else:
    print("Number is odd")

Other Python code examples you should check out:

Output

Here’s the output of the above program.

python program to check number is odd or even

Must check out Python code snippets: