Articles

Python program to check if a number is odd or even

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!

Few important tips about this program

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

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

About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :    Published Date : Feb 02,2021  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!