Pseudocode
Selection means the next statement or block to be executed depends on whether a condition is true or false. Without selection, statements simply run in the order they are written; with selection, a program can choose between different paths.
An IF statement is a selection statement. It holds a condition, and the statements inside the IF block run only when that condition is true. An ELSE branch handles the case where the condition is false, so the IF part and the ELSE part together always choose exactly one path.
bag_weight = float(input("Weight of your bag in kg: "))
if bag_weight > 23:
print("Over the limit - a fee is due")
else:
print("Bag accepted")Output when the user types 20:
Weight of your bag in kg: 20
Bag acceptedTrace it with a bag of 20 kg: 20 > 23 is false, so the IF block is skipped and only the ELSE branch runs. With a bag of 26 kg the condition is true, so the IF branch runs and the ELSE is skipped. Exactly one of the two messages is printed, never both and never neither, which is why the two branches are alternatives rather than a list of steps.
A condition compares two values using comparison operators:
| Operator | Meaning | Example condition |
|---|---|---|
== | equal to | door_code == 4821 |
< | less than | age < 13 |
> | greater than | total > 50 |
<= | less than or equal to | laps <= 10 |
>= | greater than or equal to | height >= 120 |
!= | not equal to | answer != 7 |
In Python, use these operators exactly as shown; a single = is assignment, not comparison. The indented statements under if and else belong to that branch, and the selection ends at the first statement lined up with the if.
steps = int(input("Steps walked today: "))
if steps >= 10000:
print("Daily goal reached")
else:
print("Goal not reached yet")
print("Well done for moving today")Output when the user types 12000:
Steps walked today: 12000
Daily goal reached
Well done for moving today Edexcel GCSE Computer Science · Pseudocode
Edexcel GCSE Computer Science · Variables & Constants
Edexcel GCSE Computer Science · Selection (IF)