Python program to check even or odd number

Description: Write a Python program to check whether a number is even or odd.

Rules and hints:

  • A number is even if it is divisible by 2.
  • Use the modulus operator %, which gives the remainder.

Python program to check even or odd

for number in (4, 7):
    if number % 2 == 0:
        print(number, "is even")
    else:
        print(number, "is odd")

Output:

Tutorials Class - Output Window

4 is even
7 is odd

How it works

  • 4 % 2 is 0, so 4 is even.
  • 7 % 2 is 1, so the else part runs and 7 is odd.
  • Negative numbers also work, because -3 % 2 is 1 in Python.

Learn the basics in Python Conditional Statements.


Learn more about the similar topics:
Tutorials
Python Conditional Statements
Python While Loop
Python for loop
Python Jump Statements
Exercises & Assignments
Python program to check even or odd number
Python program to find the largest of three numbers
Python program to check leap year
Python program to print multiplication table
Python program to find factorial of a number
Python program to print Fibonacci series
Python program to check prime number
Interview Questions & Answers
No Content Found.