Pseudocode vs Python for computer science exams
7 min readUpdated
Many computer science exams ask you to write algorithms in pseudocode or a high-level language. Students who code in Python often lose marks because they mix the two or skip steps. This guide shows how the two line up.
What pseudocode is for
Pseudocode is a way to describe an algorithm precisely without worrying about one language's rules. Examiners want to see clear logic: inputs, decisions, loops and outputs. Exam boards publish their own pseudocode style, so check your specification, but the ideas below are shared by all of them.
Side by side
| Idea | Typical exam pseudocode | Python |
|---|---|---|
| Assignment | total ← 0 | total = 0 |
| Input / output | INPUT name / OUTPUT name | name = input() / print(name) |
| Selection | IF x > 5 THEN ... ELSE ... ENDIF | if x > 5: ... else: |
| Count-controlled loop | FOR i ← 1 TO 10 ... NEXT i | for i in range(1, 11): |
| Condition loop | WHILE x < 10 ... ENDWHILE | while x < 10: |
| Post-condition loop | REPEAT ... UNTIL x = 0 | while True: ... if x == 0: break |
| Array | DECLARE marks : ARRAY[1:5] OF INTEGER | marks = [0] * 5 |
| Function | FUNCTION Add(a, b) RETURNS INTEGER | def add(a, b): |
Watch the loop bounds: FOR i ← 1 TO 10 includes 10, but Python's range(1, 10) stops at 9. Exam arrays often start at 1; Python lists start at 0.
Worked example: average of five marks
total ← 0
FOR i ← 1 TO 5
INPUT mark
total ← total + mark
NEXT i
average ← total / 5
OUTPUT "Average: ", averagetotal = 0
for i in range(1, 6):
mark = int(input())
total = total + mark
average = total / 5
print("Average:", average)Mistakes that lose marks
- Using Python shortcuts like
sum(marks)orsorted()when the question asks you to write the algorithm yourself. - Forgetting
ENDIF,ENDWHILEorNEXT: indentation alone is not enough in most pseudocode styles. - Not initialising a total or counter before the loop.
- Using
=for both assignment and comparison without making the meaning clear. - Missing the input validation or output the question asked for.
Tips for the exam
- Read the question for the exact inputs and outputs, then write them first.
- Use meaningful identifiers such as
totalandcount. - Indent consistently even in pseudocode; it helps the examiner follow you.
- Trace your answer with a small test value before moving on.
Frequently asked questions
Can I write Python instead of pseudocode in the exam?
Many papers accept any high-level language or pseudocode, but some questions ask for one specifically. Check the wording and your exam board's rules.
Does pseudocode have to be perfect syntax?
No, but it must be clear and unambiguous. Following your board's published style is the safest choice.
Why do exam arrays start at 1?
Some exam pseudocode lets you choose the bounds, and many questions use 1. Always use the bounds given in the question.
Learn it step by step
Practise this, step by step
Short lessons with quizzes, practice and interview questions, from your first program to job-ready.