← Python from Scratch Lesson 22 of 78 · 5 XP

Warm-up: even or odd warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

The % sign gives the remainder of a division. An even number has remainder 0 when divided by 2:

print(8 % 2)   # 0 — even
print(7 % 2)   # 1 — odd

if runs its block only when the condition is true, and else — when it is false. The block is indented by 4 spaces:

if n % 2 == 0:
    print("even")
else:
    print("odd")

Task. Read an integer and print even or odd.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.