Pseudocode
intermediate25 minLearning objectives
- Write algorithms using AQA-style pseudocode
- Translate pseudocode into Python
- Explain the purpose of structured pseudocode
Learn
AQA 4.3.3 — Pseudocode
Retrieval: the previous lesson's number-guessing flowchart represents an algorithm visually. Pseudocode represents the exact same kind of algorithm as structured text — readable like a program, but without committing to any one language's exact syntax.
AQA-style pseudocode conventions
| Construct | Pseudocode | Python equivalent |
|---|---|---|
| Assignment | total ← 0 | total = 0 |
| Selection | IF x > 10 THEN ... ELSE ... ENDIF | if x > 10: ... else: ... |
| Iteration (count-controlled) | FOR i ← 1 TO 5 ... ENDFOR | for i in range(1, 6): ... |
| Iteration (condition-controlled) | WHILE x < 10 ... ENDWHILE | while x < 10: ... |
| Input / output | INPUT x, OUTPUT x | x = input(), print(x) |
Common mistake
Forgetting the closing keyword (ENDIF, ENDWHILE, ENDFOR) — in pseudocode, indentation alone isn't considered sufficient to show where a block ends, unlike Python. Also easy to mix up: pseudocode's ← for assignment is a different symbol from =, which in pseudocode (as in maths) means equality, not assignment.
Worked example — pseudocode to Python
temperature ← INPUT
IF temperature > 30 THEN
OUTPUT "Hot"
ELSE IF temperature > 15 THEN
OUTPUT "Mild"
ELSE
OUTPUT "Cold"
ENDIF
Translated into Python:
temperature = int(input())
if temperature > 30:
print("Hot")
elif temperature > 15:
print("Mild")
else:
print("Cold")
Trace it
Trace the pseudocode above (not the Python) for temperature = 22. Which branch executes, and what is output? (22 is not > 30, but is > 15, so the "Mild" branch executes and "Mild" is output.)
Translate it the other way
Take this Python and rewrite it as AQA-style pseudocode, using the conventions table above:
total = 0
count = 0
while count < 5:
total = total + count
count = count + 1
print(total)
Challenge
Write AQA-style pseudocode for a simple grade calculator (input a percentage; output "Pass" for 40 or above, "Fail" otherwise), then implement your own pseudocode in Python and confirm both versions agree on the same test inputs.
Looking ahead: every algorithm for the rest of this sequence (Linear Search onward) will be introduced as working Python directly — but the pseudocode-to-Python translation skill from this lesson is exactly what you'd use to answer an AQA exam question that gives you an algorithm in pseudocode form.