Python Practice › If-Else Programs › Program 7
Check odd or even
Write a Python program to check whether a number is odd or even.
Input
8, 13, 0
Output
8 is even 13 is odd 0 is even
Approach
- Even numbers leave remainder 0 when divided by 2.
Solution
for n in [8, 13, 0]: if n % 2 == 0: print(n, "is even") else: print(n, "is odd")Output
8 is even 13 is odd 0 is even
Line by line
Line 2
0 % 2 is 0, so 0 is correctly reported as even.
Learn the concept
New to this topic? Read the lesson, then come back.