Write a Python Program to Check if a Number is Odd or Even

In Python, determining if a number is odd or even is a simple task.

In this tutorial, we’ll explore how to write a program that checks if a given number is odd or even.


First, let’s define what an odd number is.

An odd number is a number that is not divisible by 2.

On the other hand, an even number is a number that is divisible by 2.

Now that we understand the definitions of odd and even numbers, let’s start writing our program.

To determine if a number is odd or even in Python, we can use the modulo operator (%).

The modulo operator returns the remainder of a division operation.

If the remainder is 0, then the number is even. Otherwise, it is odd.

Here’s the Python code for our program:

number = int(input("Enter a number: "))

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

In the above code, we first ask the user to enter a number using the input() function.

The int() function is used to convert the user’s input into an integer.

Next, we use an if statement to check if the remainder of the division operation using the modulo operator is 0.

If it is, then the number is even, and we print a message saying so.

If the remainder is not 0, then the number is odd, and we print a message saying that.

Let’s run the program with a few test inputs to see if it works correctly:

Enter a number: 6
6 is even

Enter a number: 11
11 is odd

Enter a number: 0
0 is even

As we can see, the program correctly identifies whether a number is odd or even.


In conclusion, checking whether a number is odd or even in Python is a simple task that can be accomplished using the modulo operator.

By following the steps outlined above, you should be able to write a program that can determine whether a given number is odd or even.