Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find the multiple of an arbitrary numbers between two numbers

I take two numbers from the user and I have to print the numbers between them, which can be divided into 5,000, how to do this in python?

For example, a=12005 and b=28077

the result should be:
15000
20000
25000

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I don’t have an idea can you help me with it, please?

>Solution :

You can iterate all numbers with

a = 12005
b = 28077
step = 5000
for num in range(step * (a // step) + step, b, step):
    print(num)

The expression step * (a // step) calculates the largest number <= a that is divisible by step. Adding step yields the smallest number > a that is divisible by step. range(step * (a // step) + step, b, step) generate all numbers in the open range (a, b) that are divisible by step.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading