Skip to main content

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

IdeaTypical exam pseudocodePython
Assignmenttotal ← 0total = 0
Input / outputINPUT name / OUTPUT namename = input() / print(name)
SelectionIF x > 5 THEN ... ELSE ... ENDIFif x > 5: ... else:
Count-controlled loopFOR i ← 1 TO 10 ... NEXT ifor i in range(1, 11):
Condition loopWHILE x < 10 ... ENDWHILEwhile x < 10:
Post-condition loopREPEAT ... UNTIL x = 0while True: ... if x == 0: break
ArrayDECLARE marks : ARRAY[1:5] OF INTEGERmarks = [0] * 5
FunctionFUNCTION Add(a, b) RETURNS INTEGERdef 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

Pseudocodetext
total ← 0
FOR i ← 1 TO 5
    INPUT mark
    total ← total + mark
NEXT i
average ← total / 5
OUTPUT "Average: ", average
Pythonpython
total = 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) or sorted() when the question asks you to write the algorithm yourself.
  • Forgetting ENDIF, ENDWHILE or NEXT: 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 total and count.
  • 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.

Practise this, step by step

Short lessons with quizzes, practice and interview questions, from your first program to job-ready.

Python Programming course: syllabus and 1:1 mentoringCore Python from zero to functions, collections, files, OOP and algorithms.