Find elements

program to display even and odd number in the given range

Program to display even and odd number in the given range

In thid tutorial, we will discuss a concept of Python program to display even and odd number in the given range

when you devide a number by two and if the balance is zero, it is an even number

the odd number divided by two  and if the balance is one, it is an odd number

Display even and odd number in the given range

Example of even number 2,4,6,8,…..

Example of odd number 1,3,5,7,…..

 

Here we will use a modular operator to display odd or even number in the given range.

if n%2==0,  n is a even number

if n%2==1,  n is a odd number

 

This program allows the user to enter two different digits and then, the program will display odd numbers and even numbers between entered digits using for loop

Program 1

Lower_Num=int(input("Enter the first number for range: "))
Upper_Num=int(input("Enter the second number for range: "))

print("Display the even numbers between two numbers are: ")
for i in range(Lower_Num,Upper_Num+1):
    if(i%2==0):
        print(i)

print("Display the odd numbers between two numbers are: ")
for i in range(Lower_Num,Upper_Num+1):
    if(i%2==1):
        print(i)

 

When the above code is executed, it produces the following results

Enter the first number for range: 23
Enter the second number for range: 34
Display the even numbers between two numbers are: 
24
26
28
30
32
34
Display the odd numbers between two numbers are: 
23
25
27
29
31
33

 

Suggested for you

for loop in Python

If statements in Python

 

Similar post

Python program check whether a number is odd or even

Python program to check a number is even or odd using the function

Python program to print odd and even numbers without if

Python code to display all even and odd numbers from 1 to n

 

 

 

Cpp program to display even and odd number in the given range
Java program to calculate sum of odd and even numbers
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago