Divisible Numbers in Range

Write a Python program that prints all the numbers from 0 to n that are divisible by m. Both n and m are inputs from the user.

Example 1:

Input: n = 10, m = 2 

Output: 0, 2, 4, 6, 8, 10

Example 2:

Input: n = 20, m = 5 

Output: 0, 5, 10, 15, 20

You can use a for loop to iterate over the range and use the modulo operator to check divisibility.

def print_divisible_numbers(n, m):
    for i in range(n+1):
        if i % m == 0:
            print(i)

print_divisible_numbers(10, 2)

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!