← All tools

Programming Concepts – Part 2

Selection, conditions, IF/ELSE IF/ELSE, nested IF and SWITCH/CASE — with key meanings, a flowchart diagram, three hands-on challenges, a timed 25-question quiz with shuffled answers, a keyword matching game, a true/false speed round, and help for Task 2 at the bottom.

Key Meanings

The important terms from this lesson, grouped by topic.

Selection & Conditions

Selection
Lets a program choose between different paths of code depending on whether a condition is True or False.
Condition
A test that evaluates to either True or False — e.g. age >= 18.
Comparison operators
== != > < >= <= — used to build a condition.
= vs ==
= assigns a value to a variable; == compares two values for equality.

IF / ELSE IF / ELSE

IF statement
Runs a block of code only if its condition is True.
ELSE
Runs a block of code if the IF condition (and any ELSE IF conditions) were False.
ELSE IF (elif)
Checks another condition, but only if the earlier IF (or ELSE IF) was False.
Order matters
Conditions are checked top to bottom — the first one that's True is the branch that runs, and the rest are skipped.

Nested IF

Nested IF
An IF statement placed inside another IF (or ELSE) statement.
Why use one?
So a second condition is only checked once the first condition is already known to be True.
Watch out for
Nesting too many IFs can make code harder to read and trace through.

SWITCH / CASE

SWITCH/CASE
Chooses between several fixed, known values of a single variable — a tidy alternative to a long ELSE IF chain.
default
The case that runs if none of the other cases match.
When to use ELSE IF instead
When you're checking a range of values or several different conditions, not just one variable's exact values.

Flowcharts & Tracing

Flowchart
A diagram that shows the steps of an algorithm using standard symbols, connected by arrows.
Decision (diamond) symbol
One way in, two ways out — represents a selection in a flowchart.
Trace
To follow a program step by step, working out exactly what it will output.

How Selection Looks in a Flowchart

The diamond is the decision symbol — one way in, two ways out. Here's selection in action.

Decision symbol = diamond (one way in, two ways out)

Start
OUTPUT "Go to the prom with me?"
INPUT answer
answer == "yes"?
YES
OUTPUT "Yay!"
NO
OUTPUT "Forever alone"

↓ both paths lead on to

End

Match the Flowchart Symbol

Drag each symbol name (or click one, then click a definition) onto what it represents.

Match each flowchart symbol below to what it represents.

Oval
Parallelogram
Diamond
Rectangle
Arrow

Shows the start or end of the algorithm.

Drop here

Shows an input or output step.

Drop here

Shows a decision — one way in, two ways out.

Drop here

Shows a process or calculation step.

Drop here

Shows the direction the flow moves in, connecting the symbols together.

Drop here

Predict the Output

Trace through each piece of code and work out exactly what it will print, then pick your answer.

Fix the Bug

This program has four errors in it. Work out the correct version of each highlighted line.

temp = int(input("Enter temperature: "))
if temp = 30
    print("Hot day")
else
print("Not hot")

Test Yourself — 25 GCSE-Style Questions

Selection, conditions, IF/ELSE IF/ELSE, nested IF, SWITCH/CASE — and a few code-tracing questions. A timer starts as soon as you press Start, and the answer options are shuffled into a new order every question.

Keyword Match Game

A timed matching game — match each keyword to its correct meaning. The clock starts on your first move, and the terms shuffle into a new order every time you play.

Drag each keyword (or click one, then click a meaning) onto the definition it matches.

Speed Round — True or False

15 rapid-fire statements about this lesson. You've got 10 seconds per statement — answer before the bar runs out!

Task 2 Help

Stuck on Task 2? Expand a hint below — the example code is there to check your work against once you've had a proper go yourself, not to copy and paste (the code can't be selected or copied).

1. Predict & Trace

Work out what this program prints when score is 85, then 60, then 30 — then check your answers against the example.

Tips

  • The task's pseudocode uses then and endif — real Python doesn't use then, and uses a colon plus indentation instead of endif.
  • Work through the conditions from top to bottom — the first one that's True is the branch that runs.
  • Once a branch has run, Python skips the rest of the elif/else chain completely.
Show example
score = int(input("Enter score: "))

if score >= 80:
    print("Excellent")
elif score >= 50:
    print("Pass")
else:
    print("Try again")

2. Fix the Errors

The buggy version in your task has four errors — a wrong comparison operator, two missing colons, and one missing indent. Here's the corrected version to check against.

Tips

  • temp = 30 only assigns a value — you need temp == 30 to compare it.
  • Every if and else line needs a colon : at the end.
  • The line under else must be indented so Python knows it belongs to that block.
Show example
temp = int(input("Enter temperature: "))

if temp == 30:
    print("Hot day")
else:
    print("Not hot")

3. Nested IF — Cinema Pricing

Write a program using a nested IF that charges £5 for under-12s, £7 for students, and £10 for everyone else.

Tips

  • Check the under-12 condition first — if it's True, nothing else needs checking.
  • Only ask if someone is a student once you already know they're 12 or over — that's the nested part.
  • input() always returns a string, so cast the age to int() before comparing it with <.
Show example
age = int(input("How old are you? "))

if age < 12:
    print("Price: £5")
else:
    student = input("Are you a student? (yes/no) ")
    if student == "yes":
        print("Price: £7")
    else:
        print("Price: £10")