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 −


 Live Demo

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):


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


  • 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.

Updated on: 16-Apr-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started