In this post, you will learn a Python Program to Check Even or Odd Numbers with detailed explanation and algorithm but before we dive into the coding part, let us first understand what is an even and odd number.

What is an Even and Odd number?

A number that is divisible by 2 is known as an Even number whereas a number that is not divisible by 2 is known as an Odd number.

For Example: 2, 4, 6, 8, 10 are even numbers, while 1, 3, 5, 7, 9 are odd numbers.

Example for Even and Odd numbers

Algorithm to Check Even or Odd Number

  1. Take the input from the User (num)
  2. check if num % 2 == 0then print num is Even.
  3. else print num is Odd.

These three basic steps you have to follow to write a python program to check even or odd numbers.

But before writing this program few programming concepts you have to know:

  1. how to take input from the user &
  2. if-else

Source Code

num = int(input("Enter a number to check Odd and Even: "))

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

Output-1

Enter a number to check Odd and Even: 9
9 is Odd Number

Output-2

Enter a number to check Odd and Even: 8
8 is Even Number

Let us modify the above program and write it using the function.

Python Program to Check Even or Odd Number Using the function

Before writing this program few programming concepts you have to know:

  1. how to take input from the user &
  2. if-else
  3. Python Functions

Source Code

def isEven(num):
    if num %2 == 0:
        return f"{num} is Even number"
    else:
        return f"{num} is Odd number"

number = int(input("Enter a number to check Odd and Even: "))

print(isEven(number))

Output-1

Enter a number to check Odd and Even: 15
15 is Odd number

Output-2

Enter a number to check Odd and Even: 12
12 is Even number

Author

Hi, I'm Yagyavendra Tiwari, a computer engineer with a strong passion for programming. I'm excited to share my programming knowledge with everyone here and help educate others in this field.

Write A Comment