- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Python Program to Print all Numbers in a Range Divisible by a Given Number

When it is required to print all the elements in a given range that is divisible by a specific number, a simple for loop can be used.

Below is a demonstration of the same −

## Example

lower_num = int(input("Enter lower range limit...")) upper_num = int(input("Enter upper range limit...")) div_num = int(input("Enter the number that should be divided by...")) for i in range(lower_num,upper_num+1): if(i%div_num==0): print(i)

## Output

Enter lower range limit...3 Enter upper range limit...8 Enter the number that should be divided by...2 4 6 8

## Explanation

The upper and lower range of numbers is taken as input from the user.

The number by which the range of numbers have to be divided is also taken by the user.

The lower and upper range are iterated over, and if the number is divisible, it is printed on the screen.

This is the output.

- Related Articles
- Golang Program to Print all Numbers in a Range Divisible by a Given Number
- Python program to print all the numbers divisible by 3 and 5 for a given number
- C# program to print all the numbers divisible by 3 and 5 for a given number
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- Program to print all palindromes in a given range in C++
- Golang Program to Print Odd Numbers Within a Given Range
- Program to print all the numbers divisible by 3 and 5 in C++
- Count the numbers divisible by ‘M’ in a given range in C++
- Print all Good numbers in given range in C++
- Program to print prime numbers in a given range using C++ STL
- Count numbers in a range that are divisible by all array elements in C++
- Golang Program to print all integers between a range that aren't divisible by either 2 or 3
- Python Program for Efficient program to print all prime factors of a given number
- Program to find out the number of special numbers in a given range in Python

Advertisements