Check divisibility by 12

EasyIf-Else Programs · 40 of 64

Write a Python program to check whether a number is divisible by 12.

Advertisement
Input
121, 144
Output
121 False
144 True

Approach

  1. Check n % 12 == 0.

Solution

Python
for n in [121, 144]:    if n % 12 == 0:        print(n, True)    else:        print(n, False)
Output
121 False
144 True

Line by line

Line 2

121 leaves a remainder of 1, so it is not divisible by 12.

Note

The original sample output said True for 121, but 121 / 12 is 10 remainder 1, so the correct answer is False.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs