How to Get Numbers Divisible by a Given Number in Python


In this example, we will learn how to find out all numbers within a given range that can be divisible by a given number in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

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

Output:

Please input the lower limit: 10
Please input the upper limit: 100
Please input the number to be divided: 15
15
30
45
60
75
90
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments