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
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
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
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…