by BehindJava

Write a program to Print all Numbers in a Range Divisible by a Given Number in Python

Home » python » Write a program to Print all Numbers in a Range Divisible by a Given Number in Python

In this tutorial we are going to learn about writing a program to Print all Numbers in a Range Divisible by a Given Number in Python.

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

lower=int(input("Enter lower range limit:"))
upper=int(input("Enter upper range limit:"))
n=int(input("Enter the number to be divided by:"))
for i in range(lower,upper+1):
    if(i%n==0):
        print(i)

Explanation

  1. User must enter the upper range limit and the lower range limit.
  2. Then the user must enter the number to be divided from the user.
  3. The value of i ranges from the lower limit to the upper limit and upper +1 is taken because the last number is excluded in range, so to overcome that we add a number which is not necessary.
  4. Whenever the remainder of the number divided by i is equal to 0, i is printed.