Skip to content
Menu

Year 10 (ages 14–15, Grade 9 in the US) · Computing · GCSE programming · Lesson 3

Selection: if, elif and else

Making decisions in Python with if, elif and else, comparison operators, Boolean operators (and, or, not), indentation, and nested selection.

Exam boards: this lesson matches the AQA and Pearson Edexcel GCSE computing courses. Check which course your school follows.

Whiteboard video lesson: Selection: if, elif and else

8-minute video lesson

Teaching, worked examples and 20 practice questions solved step by step.

Watch free for a month

What your child will learn

  • Use comparison operators
  • Write if, elif and else statements
  • Combine conditions with and, or, not
  • Trace nested selection

The method

  1. A condition is True or False.
  2. if → elif → else: first True branch runs, then stop.
  3. Indent the code inside each branch.
  4. and: both True; or: at least one True; not: reverses.

Key words: selection, condition, comparison operator, Boolean operator, indentation.

Worked examples

Worked examples from the lesson, with every step.

Question 1

What is output when temp = 25? c:if temp > 30: c: print("Hot") c:elif temp > 20: c: print("Warm") c:else: c: print("Cool")

  1. Step 1: 25 > 30? False
  2. Step 2: 25 > 20? True → Warm

Answer: Warm

Question 2

Same program: what is output when temp = 30?

  1. Step 1: 30 > 30? False
  2. Step 2: 30 > 20? True

Answer: Warm

Question 3

Evaluate: (5 > 3) and (2 > 4)

  1. Step 1: True and False
  2. Step 2: Both must be True

Answer: False