KnowledgeBoat Logo

Computer Science

Write a Python program to print every integer between 1 and n divisible by m. Also report whether the number that is divisible by m is even or odd.

Python

Python Control Flow

23 Likes

Answer

m = int(input("Enter m: "))
n = int(input("Enter n: "))
for i in range(1, n) :
    if i % m == 0 :
        print(i, "is divisible by", m)
        if i % 2 == 0 :
            print(i, "is even")
        else :
            print(i, "is odd")

Output

Enter m: 3
Enter n: 20
3 is divisible by 3
3 is odd
6 is divisible by 3
6 is even
9 is divisible by 3
9 is odd
12 is divisible by 3
12 is even
15 is divisible by 3
15 is odd
18 is divisible by 3
18 is even

Answered By

9 Likes


Related Questions