Python Practice › If-Else Programs › Program 40
Check divisibility by 12
Write a Python program to check whether a number is divisible by 12.
Input
121, 144
Output
121 False 144 True
Approach
- Check
n % 12 == 0.
Solution
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.
Learn the concept
New to this topic? Read the lesson, then come back.