Python Program to Print Odd and Even Numbers

Writing a program to check whether a number is even or odd is one of the first algorithms we write when learning a new programming language. In this article, I’ll walk you through how to write a Python program to print odd and even numbers.

Python Program to Print Odd and Even Numbers

Odd numbers are numbers that are not divisible by 2 and even numbers are numbers that are divisible by 2. So to write a program that prints whether a number is even or odd, we can divide the number by 2 and check if the remainder is 0 or not.

If the remainder is 0 then it is an even number and if the remainder is not 0 then it is an odd number. If you are new to computer science, be aware that if we use “/” to divide the numbers, we will get a quotient as an output, but we need to find the remainder for which we need to use “%” between two numbers.

So to print the odd and even numbers using Python we need to use the “%” symbol to find the remainder after the division of two numbers. Below is how you can write a Python program to print odd and even numbers between a range of values:

Output:
0  is even
1  is odd 
2  is even
3  is odd 
4  is even
5  is odd 
6  is even
7  is odd
10  is even
11  is odd
12  is even
13  is odd
14  is even
15  is odd
16  is even
17  is odd
18  is even
19  is odd

Also, Read – Python Projects with Source Code.

Summary

So this is how we can find odd and even numbers using Python from a range of values. You can use the same logic to take a number as user input and print it whether it’s odd or even. I hope you liked this article on how to write a Python program to find odd and even numbers. Feel free to ask your valuable questions in the comments section below.

Default image
Aman Kharwal
Coder with the ♥️ of a Writer || Data Scientist | Solopreneur | Founder
Articles: 1054

Leave a Reply