Before you write a single line of Python, it helps to plan what your program is going to do. Pseudocode is a way of writing out the steps of an algorithm in a mixture of plain English and programming-style structure — clear enough for a programmer to understand, but not tied to any particular language's rules.
What Is Pseudocode?
The word "pseudo" means "fake" or "not real". Pseudocode is fake code: it describes the logic without the strict rules of a real language. There is no single standard, but most pseudocode shares certain conventions.
Why Use Pseudocode?
- You can focus on the logic without worrying about syntax errors.
- It is language-independent — you can use the same pseudocode to write in Python, JavaScript, or any other language.
- It is easier for non-programmers (like a client or a teacher) to read.
- Catching a logical mistake in pseudocode is faster than hunting through hundreds of lines of code.
Professional software engineers regularly sketch algorithms in pseudocode during design meetings before any code is written. It is a communication tool as much as a planning tool.
Basic Pseudocode Conventions
| Concept | Pseudocode example |
|---|---|
| Input | INPUT name |
| Output | OUTPUT "Hello, " + name |
| Assignment | SET score ← 0 |
| Arithmetic | SET total ← price * quantity |
| Condition | IF score > 50 THEN ... ENDIF |
| Loop (count) | FOR i ← 1 TO 10 DO ... ENDFOR |
| Loop (condition) | WHILE answer ≠ "quit" DO ... ENDWHILE |
There is flexibility in how you write these — different schools and exam boards use slightly different styles. The key is to be consistent.
A Simple Example
Task: ask the user for two numbers and display their sum.
Pseudocode:
INPUT firstNumber
INPUT secondNumber
SET total ← firstNumber + secondNumber
OUTPUT "The sum is: " + total
Python translation:
first_number = float(input("Enter first number: "))
second_number = float(input("Enter second number: "))
total = first_number + second_number
print("The sum is:", total)
Notice how the pseudocode maps directly onto the Python, just with less strict formatting.
Write pseudocode at the level of detail you actually need. For a simple task, one line per step is enough. For complex logic, add more detail. The goal is clarity, not perfection.
A More Complex Example
Task: find the largest number in a list.
SET maximum ← first item in list
FOR EACH number IN list DO
IF number > maximum THEN
SET maximum ← number
ENDIF
ENDFOR
OUTPUT "The maximum is: " + maximum
Pseudocode should communicate intent clearly. If someone reading it has to guess what you mean, it is not clear enough. Avoid abbreviating so much that the logic becomes ambiguous.
Pseudocode in Exams
GCSE and equivalent exams often ask you to write pseudocode for a given algorithm, or to trace (follow) an existing piece of pseudocode and state what it outputs. Practising pseudocode helps with both.
Practice Problems
Write pseudocode for a program that asks the user for their age and outputs 'Adult' if they are 18 or over, or 'Minor' if they are under 18.
Show answer
What is the main advantage of writing pseudocode before coding? Give a specific example.