Example HTML page

A Python program to print all numbers in a range divisible by a given Number.

In this post i am going to depict how to print all the numbers in a given range divisible by a given number.

Program

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

 Output

Enter lower range limit: 2

Enter upper range limit:35

Enter the number to be divided by:3

3

6

9

12

15

18

21

24

27

30

33

Explanation

In the above program the upper range and lower are taken from the user and are stored in the variables ‘a’ and ‘b’ respectively. We have taken an input number to be divided by from the user and is stored in ‘num’ variable. Using for loop we print all the factors of that divisible number. When the remainder of the number divided by is equal to 0, then ‘x’ is printed.

TestCase 2

Enter lower range limit:7

Enter upper range limit:40

Enter the number to be divided by:5

10

15

20

25

30

35

40

In case 2 test case we have given the lower limit 7 but the number to be divided by is 5. After the number 7 the next immediate factor of 5 is 10. Hence it prints from 10.

 

 

 

Example HTML page

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest