Check odd or even

EasyIf-Else Programs · 7 of 64

Write a Python program to check whether a number is odd or even.

Advertisement
Input
8, 13, 0
Output
8 is even
13 is odd
0 is even

Approach

  1. Even numbers leave remainder 0 when divided by 2.

Solution

Python
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.

Advertisement

Learn the concept

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

More if-else programs

← All 64 If-Else Programs