Articles

Python program to check if a number is odd or even

In this python programming guide, we will learn to write:

• program to check if a number is odd or even in python

Program to check if a number is odd or even in Python

The python program to check if a number is odd or even is as follows:

# Owner : TutorialsInhand Author : Devjeet Roy

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

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

The output of the python program to check if a number is odd or even is as follows:

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter a number: 8
The number is even!

1. We take an input from the user and convert it to an integer data type.

2. If the number on being divided by two, leaves a remainder zero, then it is an even number. Else it is an odd number.

Snapshot to write a program in python to input a number and check if the number is odd or even

Basic Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com