
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
Python program to print all even numbers in a range
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given a range, we need to print all the even numbers in the given range.
The brute-force approach is discussed below −
Here we apply a range-based for loop which provides all the integers available in the input interval.
After this, a check condition for even numbers is applied to filter all the odd numbers.
This approach takes O(n) + constant time of comparison.
Now let’s see the implementation below −
Example
start, end = 10, 29 # iteration for num in range(start, end + 1): # check if num % 2 == 0: print(num, end = " ")
Output
10 12 14 16 18 20 22 24 26 28
All the variables and functions are declared in a global frame as shown in the figure below.
Conclusion
In this article, we learned about the approach to print even numbers in the input range.
- Related Articles
- Python program to print all odd numbers in a range
- Python program to print even numbers in a list
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Golang Program to Print all Numbers in a Range Divisible by a Given Number
- Python Program to Print Numbers in a Range (1,upper) Without Using any Loops
- Python program to print all Prime numbers in an Interval
- Print all Good numbers in given range in C++
- Program to print all palindromes in a given range in C++
- Golang Program to Print Odd Numbers Within a Given Range
- Python program to print even length words in a string
- Python program to print all Disarium numbers between 1 to 100
- Program to print prime numbers in a given range using C++ STL
- Program to find all contiguously increasing numbers in start end range in Python
- Python Program to Find All Numbers which are Odd and Palindromes Between a Range of Numbers
- Python program to print all Happy numbers between 1 and 100

Advertisements