← Python course

Lesson 03

Making decisions

if / else — doing different things depending on what's true.

Right now your programs run the same way every time. Real programs branch — they react to what's happening.

Loading editor…

if age >= 13: asks a yes/no question. If it's true, the indented lines under it run. If it's false, Python skips to else: instead. Indentation isn't decoration in Python — it's how the computer knows which lines belong to which branch. Four spaces, every time.

The question itself uses comparison operators:

You can chain more conditions with elif ("else if"):

Loading editor…

Python checks each elif top to bottom and stops at the first one that's true. Order matters.

You can also combine conditions with and / or:

Loading editor…

True and False (capital letters, no quotes) are booleans — the actual yes/no values Python uses internally.

Your turn

Write a program that checks a number and prints "Even" or "Odd". Hint: number % 2 gives the remainder after dividing by 2 — it's 0 for even numbers.

Loading editor…

Next: doing something many times without retyping it — loops.