CBSE Class 11 Computer Science Question 142 of 161

Flow of Control — Question 19

Back to all questions
19
Question

Question 19

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.

Solution
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
Answer