Write a Python Program to Check Whether the Given Number is Even or Odd
Introduction
A number is even if it is divisible by 2, and odd if it is not divisible by 2. In Python, we use the modulus operator % to check the remainder.
Logic to Write the Code
- Start the program.
- Take a number as input from the user.
- Check if the number is divisible by 2 using
%operator. - If remainder is 0, print “Even”.
- Otherwise, print “Odd”.
- End the program.
Source Code (Beginner Friendly)
# Python program to check even or odd number
# Taking input from user
num = int(input("Enter a number: "))
# Checking even or odd
if num % 2 == 0:
print("The number is Even")
else:
print("The number is Odd")
Sample Output
Enter a number: 10
The number is Even
Enter a number: 7
The number is Odd
Viva Questions with Answers
1. What is an even number?
An even number is divisible by 2.
2. What is an odd number?
An odd number is not divisible by 2.
3. Which operator is used to check divisibility?
The modulus operator %.
4. What does num % 2 return?
It returns the remainder after dividing the number by 2.
5. Why do we use int() with input()?
Because input() takes data as string, so we convert it to integer.
