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

This is a Python Program to print all numbers in a range divisible by a given number.

Problem Description

The program prints all numbers in a range divisible by a given number.

Problem Solution

1. Take in the upper range and lower range limit from the user.
2. Take in the number to be divided by from the user.
3. Using a for loop, print all the factors which is divisible by the number.
4. Exit.

Program/Source Code

Here is the source code of the Python Program to print all numbers in a range divisible by a given number. The program output is also shown below.

 
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)
Program 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.
4. Whenever the remainder of the number divided by i is equal to 0, i is printed.

advertisement
advertisement
Runtime Test Cases
 
Case 1:
Enter lower range limit:1
Enter upper range limit:50
Enter the number to be divided by:5
5
10
15
20
25
30
35
40
45
50
 
Case 2:
Enter lower range limit:50
Enter upper range limit:100
Enter the number to be divided by:7
56
63
70
77
84
91
98

Sanfoundry Global Education & Learning Series – Python Programs.

To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.