Articles

Program to find all even numbers within an interval in Python

Program to find all even numbers within an interval in Python


In this python programming article, we are going to learn

  • python program to find even numbers in a given range

Program to find the even numbers within a range in Python

The python program to find even numbers in a given range is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

lower_limit = int(input("Enter lower limit: "))
upper_limit = int(input("Enter upper limit: "))

for i in range(lower_limit, upper_limit+1):
    if i % 2 == 0:
        print(i, end=" ")

The output of the python program to find even numbers in a given range is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter lower limit: 7
Enter upper limit: 21
8 10 12 14 16 18 20 

Few important tips about this program

1. We take the lower and upper limit from the user and convert each one of them to integer data type.

2. Then within the range we find all the even numbers. Both the limites are inclusive in the range.

3. The logic is , a number is even if after divided by 2 the remainder is 0.

 

Python program to find even numbers in a given range snapshot:

python program to find even numbers in a given range

 


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 : Aug 26,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!