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

Program to check if a number is odd or even in Python. This program involves conceptual maths and If -else statement. It is useful for beginners, class 11,12 and B Tech computer science students. Download source code.

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

What is odd and even number ?

Odd and Even numbers:
If you divide a number by 2 and it gives a remainder of 0 then it is known as even number, otherwise an odd number.
Even number examples: 2, 4, 6, 8, 10, etc.
Odd number examples:1, 3, 5, 7, 9 etc.

Source code :

num = int(input("Enter a number: "))  
if (num % 2) == 0:  
   print("{0} is Even number".format(num))  
else:  
   print("{0} is Odd number".format(num)) 

Download Source code : For Download Click on the below Button

Step by step Explaination :

Step 1. Number which is to be checked is captured.
num = int(input(“Enter a number: “))
Step 2. If and else loop with odd or even logic
if (num % 2) == 0:
The % mark here shows the remainder after dividing the captured integer by 2.
Step 3. If number is even then print ” {number} is even number.
print(“{0} is Even number”.format(num))
Step 4. Else print number is odd.
else: print(“{0} is Odd number”.format(num))

Output :

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
 RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/test1.py 
Enter a number: 5
5 is Odd number
>>> 
 RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/test1.py 
Enter a number: 6
6 is Even number
>>> 

Output Explanation :

Number to be checked is captured.
Enter a number: 5
Check is calculated through if -else statement in python program.
5 is odd number.
similarly,
Enter a number: 6
6 is Even number

Conclusion :

Number is captured and after checking whether its odd or even it is printed.

Thank you for reading and learning from Program to check if a number is odd or even in Python post. It includes mathematical theory knowledge and if and else statement knowledge. This is one of the basic program for beginners, class 11,12 and B Tech computer science students. Below we have provided many more basic programs and practical file for class 11 and 12.

Python Programs Archives – CS Study

Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study

Computer Science Practical file for class 12 Term-2 – CS Study

Leave a Comment

Your email address will not be published. Required fields are marked *