Decisions in code

About this lesson: Decisions in code

In short

In Python, if checks a condition and else handles everything else. The colon and the indent (4 spaces) show which lines belong to each part. Change the age.

Decisions in code

What you'll explore

if and else: A two-way choice in Python
In Python, if checks a condition and else handles everything else. The colon and the indent (4 spaces) show which lines belong to each part.
elif: More than two choices
elif means ‘else if’. Python checks each condition from the top and runs only the first one that is True.
Order matters: Put the strictest test first
Because Python stops at the first True condition, the order can cause a bug. Set the score to 85 and look at the output, then swap the order.
Check yourself: Indent it
Ben writes if lives == 0: on one line, and print("Game over") on the next line, starting right at the left edge. Python shows an error.

Also in this lesson

  • Common mix-ups
  • Python patterns
  • Your own menu

Words to know

if
Runs code only when a condition is True.
elif
Checks another condition if the earlier ones were False.
else
Runs when no condition was True.
indentation
Spaces at the start of a line that show which block it belongs to.
==
Compares two values for equality.

Sources

  • Python documentation: if statements

An interactive lesson with a live experiment: move the sliders, press the buttons and answer quick questions. 4 short steps and a 6-question quiz. Part of the Family plan. Written and checked by Shalo Lab. Last updated 11 November 2026.

← Breaking a problem down · Data types and constants →

All lessons in Term 3 · Computing · Age 12