Skip to content
Reference

Pseudocode ↔ Python

Every construct from the Cambridge pseudocode guide, with the Python you'd write in Paper 4. Filter for your syllabus and bookmark this. Try any snippet in the Playground → — complete Python programs have a Run Python button that opens them in the Python Playground.

Source: Cambridge 9618 Pseudocode Guide for TeachersFor examination in 2027, 2028 and 2029

Pseudocode string manipulation functions will always be provided in examinations (§5.5). Any pseudocode functions used in an examination will be defined (§8).

Changes this year: 2026 → 2027–29: no changes to syntax or functions. Only fix: the Cat class example in §10.2 now declares Breed : STRING (was INTEGER).

37 constructs. Badges mark the ones that belong to one syllabus only.

§1 How pseudocode appears in the exam §1.1–1.5

Monospaced font, three-space indentation, keywords in UPPER CASE, identifiers in MixedCase, meta-variables in <angle brackets>. Comments start with // and run to the end of the line.

Comments (§1.5) — the guide's own example

Run Run Python VB.NET · Java
CAIE pseudocode
// this procedure swaps
// values of X and Y
PROCEDURE SWAP(BYREF X : INTEGER, Y : INTEGER)
DECLARE Temp : INTEGER
Temp X // temporarily store X
X Y
Y Temp
ENDPROCEDURE
Python# this procedure swaps
# values of x and y
def swap(x, y):
    return y, x

💡 Note the guide: when several parameters use the same method, BYREF need not be repeated — here Y is also BYREF. The guide leaves Temp undeclared; the Playground (like an examiner) expects the DECLARE.

Meta-variables (§1.3)

Run Python
CAIE pseudocode
REPEAT
<statement(s)>
UNTIL <condition>
Python# <…> means “substitute something here”

💡 Angle brackets are never typed in real code — they show where your own statements/conditions go.

§2 Variables, constants & data types §2.1–2.6

Six basic types: INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE. Declare before use. Identifiers: letters, digits, underscore; start with a letter; case-insensitive. Assignment is ←.

CAIE pseudocode
DECLARE Count : INTEGER // 5, -3
DECLARE Price : REAL // 4.7, 0.3, -4.0 (a digit each side of the point)
DECLARE Grade : CHAR // 'x', 'C', '@' (single quotes)
DECLARE Name : STRING // "This is a string", "" (double quotes)
DECLARE Found : BOOLEAN // TRUE, FALSE
DECLARE DOB : DATE // 02/01/2005 (dd/mm/yyyy)
Count -3
Price 4.7
Grade 'C'
Name ""
Found TRUE
DOB 02/01/2005
OUTPUT Count, " ", Price, " ", Grade, " ", Found, " ", DOB
Pythoncount = -3
price = 4.7
grade = 'C'
name = ""
found = True
from datetime import date
dob = date(2005, 1, 2)

💡 DATE is a 9618 type only — 2210 has just INTEGER, REAL, CHAR, STRING and BOOLEAN.

Variable declarations (§2.4)

Run Run Python VB.NET · Java
CAIE pseudocode
DECLARE Counter : INTEGER
DECLARE TotalToPay : REAL
DECLARE GameOver : BOOLEAN
Pythoncounter: int = 0
total_to_pay: float = 0.0
game_over: bool = False

💡 Format: DECLARE <identifier> : <data type>. In 9618 you are expected to declare every variable.

CAIE pseudocode
CONSTANT HourlyRate = 6.50
CONSTANT DefaultText = "N/A"
OUTPUT HourlyRate * 40, " ", DefaultText
PythonHOURLY_RATE = 6.50
DEFAULT_TEXT = "N/A"

💡 Only a literal may be the value of a constant — never a variable, another constant or an expression. (The Playground enforces this.)

Assignment (§2.6)

Run VB.NET · Java
CAIE pseudocode
DECLARE Counter, NumberOfHours : INTEGER
DECLARE TotalToPay : REAL
CONSTANT HourlyRate = 6.50
Counter 0
Counter Counter + 1
NumberOfHours 12
TotalToPay NumberOfHours * HourlyRate
OUTPUT Counter, " ", TotalToPay
Pythoncounter = 0
counter = counter + 1
total_to_pay = number_of_hours * HOURLY_RATE

💡 The operator is ← (you may write <- in exams). A single = is comparison, not assignment.

§3 Arrays §3.1–3.2

Fixed-length, one data type, consecutive indices. State the lower bound explicitly — usually 1. Two-dimensional arrays use two ranges.

Declaring arrays (§3.1)

Run Run Python VB.NET · Java
CAIE pseudocode
DECLARE StudentNames : ARRAY[1:30] OF STRING
DECLARE NoughtsAndCrosses : ARRAY[1:3,1:3] OF CHAR
Pythonstudent_names = [""] * 30
noughts_and_crosses = [[' '] * 3 for _ in range(3)]

💡 Python lists start at 0, so StudentNames[1] ↔ student_names[0].

Accessing elements (§3.2)

Run VB.NET · Java
CAIE pseudocode
DECLARE StudentNames : ARRAY[1:30] OF STRING
DECLARE NoughtsAndCrosses : ARRAY[1:3,1:3] OF CHAR
DECLARE n : INTEGER
n 1
StudentNames[1] "Ali"
NoughtsAndCrosses[2,3] 'X'
StudentNames[n+1] StudentNames[n]
OUTPUT StudentNames[2], " ", NoughtsAndCrosses[2,3]
Pythonstudent_names[0] = "Ali"
noughts_and_crosses[1][2] = 'X'
student_names[n] = student_names[n - 1]

Whole-array assignment & filling with a loop (§3.2)

9618 only Run Run Python VB.NET · Java
CAIE pseudocode
DECLARE StudentNames : ARRAY[1:30] OF STRING
DECLARE Backup : ARRAY[1:30] OF STRING
DECLARE Index : INTEGER
FOR Index 1 TO 30
StudentNames[Index] ""
NEXT Index
StudentNames[7] "Sara"
Backup StudentNames // allowed: same size and type
OUTPUT Backup[7]
Pythonstudent_names = [""] * 30
backup = student_names.copy()

💡 Do NOT write StudentNames[1 TO 30] ← "" — the guide says to use a loop instead.

§4 User-defined data types §4.1–4.2

Non-composite: enumerated and pointer. Composite: record, set, class/object (§10). ADTs (stack, queue, linked list, dictionary, binary tree) are built from these.

Enumerated type (§4.1)

9618 only Run Run Python VB.NET · Java
CAIE pseudocode
TYPE Season = (Spring, Summer, Autumn, Winter)
DECLARE ThisSeason, NextSeason : Season
ThisSeason Spring
NextSeason ThisSeason + 1
OUTPUT NextSeason
Pythonfrom enum import Enum
class Season(Enum):
    SPRING = 1; SUMMER = 2; AUTUMN = 3; WINTER = 4
this_season = Season.SPRING
next_season = Season(this_season.value + 1)

💡 Values have an order, so + 1 moves to the next value and < > comparisons work.

Pointer type (§4.1) — ^ declares, ^Var takes the address, Ptr^ dereferences

9618 only Run Run Python VB.NET · Java
CAIE pseudocode
TYPE TIntPointer = ^INTEGER
DECLARE MyPointer : TIntPointer
DECLARE Count : INTEGER
Count 5
MyPointer ^Count // address of Count
MyPointer^ MyPointer^ + 1 // access the value stored at the memory address
OUTPUT Count
Python# Python has no raw pointers; the closest idea is
# two names bound to one mutable object.
count = [5]
my_pointer = count
my_pointer[0] += 1
print(count[0])

💡 Declaring the pointer VARIABLE does not use ^ — only the TYPE definition, the address-of and the dereference do.

Record type (§4.1)

9618 only Run Run Python VB.NET · Java
CAIE pseudocode
TYPE StudentRecord
DECLARE LastName : STRING
DECLARE FirstName : STRING
DECLARE DateOfBirth : DATE
DECLARE YearGroup : INTEGER
DECLARE FormGroup : CHAR
ENDTYPE
DECLARE Pupil1, Pupil2 : StudentRecord
Pupil1.LastName "Johnson"
Pupil1.FirstName "Leroy"
Pupil1.DateOfBirth 02/01/2005
Pupil1.YearGroup 6
Pupil1.FormGroup 'A'
Pupil2 Pupil1
OUTPUT Pupil2.FirstName, " ", Pupil2.LastName
Pythonfrom dataclasses import dataclass
from datetime import date
@dataclass
class StudentRecord:
    last_name: str = ""
    first_name: str = ""
    date_of_birth: date = date(2000, 1, 1)
    year_group: int = 0
    form_group: str = ""
pupil1 = StudentRecord("Johnson", "Leroy", date(2005, 1, 2), 6, 'A')
import copy; pupil2 = copy.copy(pupil1)

Array of records (§4.2)

9618 only Run VB.NET · Java
CAIE pseudocode
TYPE StudentRecord
DECLARE LastName : STRING
DECLARE YearGroup : INTEGER
ENDTYPE
DECLARE Form : ARRAY[1:30] OF StudentRecord
DECLARE Index : INTEGER
FOR Index 1 TO 30 // every field must be given a value before it is read
Form[Index].YearGroup 7
NEXT Index
FOR Index 1 TO 30
Form[Index].YearGroup Form[Index].YearGroup + 1
NEXT Index
OUTPUT Form[30].YearGroup
Pythonform = [StudentRecord() for _ in range(30)]
for s in form:
    s.year_group += 1

Set type (§4.1)

9618 only Run VB.NET · Java
CAIE pseudocode
TYPE LetterSet = SET OF CHAR
DEFINE Vowels ('A','E','I','O','U') : LetterSet
DECLARE Ch : CHAR
Ch 'E'
IF Ch IN Vowels THEN
OUTPUT Ch, " is a vowel"
ENDIF
Pythonvowels = {'A', 'E', 'I', 'O', 'U'}
if ch in vowels:
    print(ch, "is a vowel")

💡 The guide defines only the declaration (TYPE … = SET OF …, DEFINE …). IN is a Playground convenience for membership.

§5 Common operations §5.1–5.6

INPUT/OUTPUT, arithmetic (+ − * / DIV MOD), relational (> < >= <= = <>), logic (AND OR NOT), the string functions the exam will always provide, and INT / RAND.

INPUT and OUTPUT (§5.1)

Run VB.NET · Java
CAIE pseudocode
DECLARE Answer : STRING
DECLARE Score, Lives : INTEGER
Score 120
Lives 3
INPUT Answer
OUTPUT Score
OUTPUT "You have ", Lives, " lives left"
Pythonanswer = input()
print(score)
print("You have", lives, "lives left")

💡 Several values separated by commas can be output in one statement.

Arithmetic (§5.2) — / always gives REAL; DIV and MOD for integers

Run Run Python VB.NET · Java
CAIE pseudocode
OUTPUT 7 / 2 // 3.5 (REAL even for integer operands)
OUTPUT 7 DIV 2 // 3 (quotient)
OUTPUT 7 MOD 2 // 1 (remainder)
OUTPUT (2 + 3) * 4 // use brackets to make order explicit
Pythonprint(7 / 2)   # 3.5
print(7 // 2)  # 3
print(7 % 2)   # 1
print((2 + 3) * 4)

Relational & logic operators (§5.3–5.4)

Run VB.NET · Java
CAIE pseudocode
DECLARE A, B : INTEGER
A 5
B 8
OUTPUT A > B, " ", A <= B, " ", A = 5, " ", A <> B
OUTPUT (A < B) AND NOT (B = 8)
OUTPUT (A > B) OR (B > A)
Pythonprint(a > b, a <= b, a == 5, a != b)
print((a < b) and not (b == 8))
print((a > b) or (b > a))

💡 Results are always BOOLEAN. Only AND, OR, NOT are used.

String functions provided in the exam (§5.5)

9618 only Run Run Python VB.NET · Java
CAIE pseudocode
OUTPUT RIGHT("ABCDEFGH", 3) // "FGH"
OUTPUT LENGTH("Happy Days") // 10
OUTPUT MID("ABCDEFGH", 2, 3) // "BCD" (start position, length)
OUTPUT LCASE('W') // 'w'
OUTPUT UCASE('h') // 'H'
OUTPUT "Summer" & " " & "Pudding" // & concatenates
Python"ABCDEFGH"[-3:]          # RIGHT
len("Happy Days")          # LENGTH
"ABCDEFGH"[1:4]           # MID(s, 2, 3) → start index 1, length 3
'W'.lower(); 'h'.upper()
"Summer" + " " + "Pudding"

💡 These are the ONLY string functions defined in the 9618 guide. LCASE/UCASE take a CHAR; a non-letter is returned unchanged. 2210 additionally uses LEFT, SUBSTRING and applies UCASE/LCASE to strings.

Numeric functions (§5.6)

9618 only Run Run Python VB.NET · Java
CAIE pseudocode
OUTPUT INT(27.5415) // 27 — the integer part
OUTPUT RAND(87) < 87 // RAND(x): random REAL from 0 up to (not including) x
OUTPUT INT(RAND(6)) + 1 // a dice roll 1–6
Pythonint(27.5415)
import random
random.random() * 87
random.randint(1, 6)

💡 2210 uses ROUND(x, places) and RANDOM() instead — both also run in the Playground.

§6 Selection §6.1–6.2

IF … THEN … [ELSE …] ENDIF and CASE OF … [OTHERWISE …] ENDCASE. There is no ELSEIF — nest IFs.

Nested IF — the guide's example (§6.1)

Run VB.NET · Java
CAIE pseudocode
DECLARE ChallengerScore, ChampionScore, HighestScore : INTEGER
DECLARE ChallengerName, ChampionName : STRING
ChallengerScore 90
ChampionScore 85
HighestScore 95
ChallengerName "Ayesha"
ChampionName "Bilal"
IF ChallengerScore > ChampionScore THEN
IF ChallengerScore > HighestScore THEN
OUTPUT ChallengerName, " is champion and highest scorer"
ELSE
OUTPUT ChallengerName, " is the new champion"
ENDIF
ELSE
OUTPUT ChampionName, " is still the champion"
IF ChampionScore > HighestScore THEN
OUTPUT ChampionName, " is also the highest scorer"
ENDIF
ENDIF
Pythonif challenger_score > champion_score:
    if challenger_score > highest_score:
        print(challenger_name, "is champion and highest scorer")
    else:
        print(challenger_name, "is the new champion")
else:
    print(champion_name, "is still the champion")
    if champion_score > highest_score:
        print(champion_name, "is also the highest scorer")

CASE with OTHERWISE — the guide's example (§6.2)

Run VB.NET · Java
CAIE pseudocode
DECLARE Move : CHAR
DECLARE Position : INTEGER
Position 50
INPUT Move
CASE OF Move
'W' : Position Position - 10
'S' : Position Position + 10
'A' : Position Position - 1
'D' : Position Position + 1
OTHERWISE : OUTPUT "Beep"
ENDCASE
OUTPUT Position
Pythonmatch move:
    case 'W': position -= 10
    case 'S': position += 10
    case 'A': position -= 1
    case 'D': position += 1
    case _: print("Beep")

💡 Cases are tested in sequence; the first that applies runs and control goes to after ENDCASE. OTHERWISE must be last.

CASE with ranges (§6.2)

Run VB.NET · Java
CAIE pseudocode
DECLARE Mark : INTEGER
Mark 67
CASE OF Mark
80 TO 100 : OUTPUT "A"
60 TO 79 : OUTPUT "B"
40 TO 59 : OUTPUT "C"
OTHERWISE : OUTPUT "U"
ENDCASE
Pythonif 80 <= mark <= 100: print("A")
elif 60 <= mark <= 79: print("B")
elif 40 <= mark <= 59: print("C")
else: print("U")

§7 Iteration §7.1–7.3

Count-controlled FOR … NEXT (inclusive, optional STEP), post-condition REPEAT … UNTIL (runs at least once), pre-condition WHILE … ENDWHILE (may run zero times).

Nested FOR loops — the guide's example (§7.1)

Run VB.NET · Java
CAIE pseudocode
CONSTANT MaxRow = 3
DECLARE Amount : ARRAY[1:3, 1:10] OF INTEGER
DECLARE Row, Column, RowTotal, Total : INTEGER
FOR Row 1 TO MaxRow
FOR Column 1 TO 10
Amount[Row, Column] Row * Column
NEXT Column
NEXT Row
Total 0
FOR Row 1 TO MaxRow
RowTotal 0
FOR Column 1 TO 10
RowTotal RowTotal + Amount[Row, Column]
NEXT Column
OUTPUT "Total for Row ", Row, " is ", RowTotal
Total Total + RowTotal
NEXT Row
OUTPUT "The grand total is ", Total
Pythontotal = 0
for row in range(MAX_ROW):
    row_total = 0
    for column in range(10):
        row_total += amount[row][column]
    print("Total for Row", row + 1, "is", row_total)
    total += row_total
print("The grand total is", total)

💡 If value1 = value2 the body runs once; if value1 > value2 it does not run at all. Repeat the identifier after NEXT.

FOR with STEP (§7.1)

Run Run Python VB.NET · Java
CAIE pseudocode
DECLARE i : INTEGER
FOR i 10 TO 1 STEP -3
OUTPUT i
NEXT i
Pythonfor i in range(10, 0, -3):
    print(i)

💡 The loop ends when the counter goes past value2. STEP may be negative.

REPEAT … UNTIL — the guide's example (§7.2)

Run Run Python VB.NET · Java
CAIE pseudocode
DECLARE Password : STRING
REPEAT
OUTPUT "Please enter the password"
INPUT Password
UNTIL Password = "Secret"
OUTPUT "Welcome"
Pythonwhile True:
    print("Please enter the password")
    password = input()
    if password == "Secret":
        break

💡 Statements run at least once; the condition is tested afterwards and TRUE ends the loop.

WHILE — the guide's example (§7.3)

Run VB.NET · Java
CAIE pseudocode
DECLARE Number : INTEGER
Number 25
WHILE Number > 9
Number Number - 9
ENDWHILE
OUTPUT Number
Pythonwhile number > 9:
    number = number - 9

💡 9618 writes WHILE <condition> with no DO (2210 writes WHILE <condition> DO). Both run in the Playground.

§8 Procedures & functions §8.1–8.3

Procedures are CALLed as complete statements; functions RETURN a value and are used inside expressions (never with CALL). Parameters are BYVAL unless BYREF is stated. Functions must not take BYREF parameters.

Procedures with and without parameters — the guide's example (§8.1)

Run VB.NET · Java
CAIE pseudocode
CONSTANT Default = 100
DECLARE Size : INTEGER
 
PROCEDURE MoveForward(Distance : INTEGER)
OUTPUT "forward ", Distance
ENDPROCEDURE
PROCEDURE Turn(Angle : INTEGER)
OUTPUT "turn ", Angle
ENDPROCEDURE
PROCEDURE Square(Size : INTEGER)
DECLARE Side : INTEGER
FOR Side 1 TO 4
CALL MoveForward(Size)
CALL Turn(90)
NEXT Side
ENDPROCEDURE
PROCEDURE DefaultSquare()
CALL Square(100)
ENDPROCEDURE
 
Size 50
IF Size = Default THEN
CALL DefaultSquare()
ELSE
CALL Square(Size)
ENDIF
Pythondef square(size):
    for side in range(4):
        move_forward(size)
        turn(90)

def default_square():
    square(100)

if size == DEFAULT:
    default_square()
else:
    square(size)

Function — the guide's example (§8.2)

Run VB.NET · Java
CAIE pseudocode
DECLARE Distance : INTEGER
Distance 7
 
FUNCTION Max(Number1 : INTEGER, Number2 : INTEGER) RETURNS INTEGER
IF Number1 > Number2 THEN
RETURN Number1
ELSE
RETURN Number2
ENDIF
ENDFUNCTION
 
OUTPUT "Penalty Fine = ", Max(10, Distance*2)
Pythondef max_(number1, number2):
    if number1 > number2:
        return number1
    return number2

print("Penalty Fine =", max_(10, distance * 2))

💡 RETURN executes immediately — later lines in the function are skipped. Do not write CALL before a function.

BYREF vs BYVAL — the guide's SWAP (§8.3)

9618 only Run VB.NET · Java
CAIE pseudocode
PROCEDURE SWAP(BYREF X : INTEGER, Y : INTEGER)
DECLARE Temp : INTEGER
Temp X
X Y
Y Temp
ENDPROCEDURE
 
DECLARE A, B : INTEGER
A 1
B 2
CALL SWAP(A, B)
OUTPUT A, " ", B
Python# Python passes references to objects; ints are immutable,
# so return the new values instead:
def swap(x, y):
    return y, x
a, b = swap(a, b)

💡 BYREF: the procedure changes the caller's variable. BYVAL (the default): it works on a copy. One BYREF keyword covers the following parameters passed the same way.

§9 File handling §9.1–9.2

Text files: OPENFILE … FOR READ | WRITE | APPEND, READFILE, WRITEFILE, EOF, CLOSEFILE. Random files: OPENFILE … FOR RANDOM, SEEK, GETRECORD, PUTRECORD.

Copy a text file, replacing blank lines — the guide's example (§9.1)

Run VB.NET · Java
CAIE pseudocode
DECLARE LineOfText : STRING
// make FileA.txt first
OPENFILE "FileA.txt" FOR WRITE
WRITEFILE "FileA.txt", "first line"
WRITEFILE "FileA.txt", ""
WRITEFILE "FileA.txt", "third line"
CLOSEFILE "FileA.txt"
 
OPENFILE "FileA.txt" FOR READ
OPENFILE "FileB.txt" FOR WRITE
WHILE NOT EOF("FileA.txt")
READFILE "FileA.txt", LineOfText
IF LineOfText = "" THEN
WRITEFILE "FileB.txt", " ----------------------------"
ELSE
WRITEFILE "FileB.txt", LineOfText
ENDIF
ENDWHILE
CLOSEFILE "FileA.txt"
CLOSEFILE "FileB.txt"
OUTPUT "copied — see the Files panel"
Pythonwith open("FileA.txt") as src, open("FileB.txt", "w") as dst:
    for line in src:
        line = line.rstrip("\n")
        dst.write((" " + "-" * 28 if line == "" else line) + "\n")

💡 WRITE creates a new file (existing data lost); APPEND adds after existing data. EOF(file) is TRUE when no lines remain. Open a file in one mode at a time.

Random-access file — the guide's example, simplified (§9.2)

9618 only Run Run Python VB.NET · Java
CAIE pseudocode
TYPE Student
DECLARE LastName : STRING
DECLARE YearGroup : INTEGER
ENDTYPE
DECLARE Pupil, NewPupil : Student
DECLARE Position : INTEGER
 
OPENFILE "StudentFile.Dat" FOR RANDOM
FOR Position 10 TO 12
Pupil.LastName "Pupil" & NUM_TO_STR(Position)
Pupil.YearGroup 6
SEEK "StudentFile.Dat", Position
PUTRECORD "StudentFile.Dat", Pupil
NEXT Position
 
// move records 12..10 up one place, then insert at 10
FOR Position 12 TO 10 STEP -1
SEEK "StudentFile.Dat", Position
GETRECORD "StudentFile.Dat", Pupil
SEEK "StudentFile.Dat", Position + 1
PUTRECORD "StudentFile.Dat", Pupil
NEXT Position
NewPupil.LastName "Johnson"
NewPupil.YearGroup 6
SEEK "StudentFile.Dat", 10
PUTRECORD "StudentFile.Dat", NewPupil
CLOSEFILE "StudentFile.Dat"
OUTPUT "done — see the Files panel"
Pythonimport pickle, os
# Python: use a fixed record size and f.seek(pos * SIZE)
# with struct/pickle, or a shelve/dbm for keyed records.

💡 SEEK moves the file pointer to a record address; GETRECORD reads the record there into a variable of the right type; PUTRECORD overwrites the record there.

§10 Object-oriented programming §10.1–10.2

Methods and properties are public unless stated; PUBLIC/PRIVATE are used when access matters. Constructors are procedures named NEW. INHERITS for subclasses; SUPER for the parent's methods; NEW <class>(…) creates an object.

Methods and properties — the guide's example (§10.1)

9618 only Run Run Python VB.NET · Java
CAIE pseudocode
CLASS PlayerClass
PRIVATE Attempts : INTEGER
PUBLIC PROCEDURE NEW()
Attempts 3
ENDPROCEDURE
PUBLIC PROCEDURE SetAttempts(Number : INTEGER)
Attempts Number
ENDPROCEDURE
PUBLIC FUNCTION GetAttempts() RETURNS INTEGER
RETURN Attempts
ENDFUNCTION
ENDCLASS
 
DECLARE Player : PlayerClass
Player NEW PlayerClass()
Player.SetAttempts(5)
OUTPUT Player.GetAttempts()
Pythonclass Player:
    def __init__(self):
        self.__attempts = 3
    def set_attempts(self, number):
        self.__attempts = number
    def get_attempts(self):
        return self.__attempts

player = Player()
player.set_attempts(5)
print(player.get_attempts())

💡 Methods are called with dot notation: Player.SetAttempts(5). A private attribute can only be reached through public methods.

Constructors and inheritance — the guide's Pet/Cat example (§10.2)

9618 only Run Run Python VB.NET · Java
CAIE pseudocode
CLASS Pet
PRIVATE Name : STRING
PUBLIC PROCEDURE NEW(GivenName : STRING)
Name GivenName
ENDPROCEDURE
PUBLIC FUNCTION GetName() RETURNS STRING
RETURN Name
ENDFUNCTION
ENDCLASS
 
CLASS Cat INHERITS Pet
PRIVATE Breed : STRING
PUBLIC PROCEDURE NEW(GivenName : STRING, GivenBreed : STRING)
SUPER.NEW(GivenName)
Breed GivenBreed
ENDPROCEDURE
PUBLIC FUNCTION Describe() RETURNS STRING
RETURN GetName() & " is a " & Breed
ENDFUNCTION
ENDCLASS
 
DECLARE MyCat : Cat
MyCat NEW Cat("Kitty", "Shorthaired")
OUTPUT MyCat.Describe()
Pythonclass Pet:
    def __init__(self, given_name):
        self.__name = given_name
    def get_name(self):
        return self.__name

class Cat(Pet):
    def __init__(self, given_name, given_breed):
        super().__init__(given_name)
        self.__breed = given_breed
    def describe(self):
        return f"{self.get_name()} is a {self.__breed}"

my_cat = Cat("Kitty", "Shorthaired")
print(my_cat.describe())

💡 Object creation: <object name> ← NEW <class name>(<param1>, <param2> …). 2026 guide typo: Breed was INTEGER; 2027–29 corrects it to STRING.

Beyond the guide: exception handling (A2 §20.3) 9618 syllabus §20.3

The official guide has no exception syntax because §20.3 is examined in Python, VB.NET or Java (Paper 4). When you plan in pseudocode, use TRY … EXCEPT … ENDTRY — it is the accepted form and the Playground runs it.

TRY … EXCEPT … ENDTRY

9618 only Run Run Python VB.NET · Java
CAIE pseudocode
DECLARE Entry : STRING
DECLARE N : INTEGER
INPUT Entry
TRY
N STR_TO_NUM(Entry)
OUTPUT 100 / N
EXCEPT
OUTPUT "Error: ", ERRORMESSAGE()
ENDTRY
OUTPUT "Still running"
Pythontry:
    n = int(entry)
    print(100 / n)
except Exception as e:
    print("Error:", e)
print("Still running")

💡 The EXCEPT block runs only if a statement inside TRY raises a runtime error (division by zero, failed conversion, index out of range, file not open…). Validation prevents predictable bad input; exception handling deals with what still goes wrong. ERRORMESSAGE() is a Playground convenience for the caught message.

2210 (O Level) differences 2210 syllabus

O Level pseudocode follows the same style. Differences you must know for Paper 2:

2210 string & maths library routines

2210 only Run Run Python VB.NET · Java
CAIE pseudocode
OUTPUT LENGTH("Computer") // 8
OUTPUT SUBSTRING("Computer", 1, 4) // "Comp" (start, length)
OUTPUT UCASE("hello") // "HELLO" — whole strings in 2210
OUTPUT LCASE("HELLO")
OUTPUT ROUND(3.14159, 2) // 3.14
OUTPUT RANDOM() < 1 // random REAL 0 ≤ x < 1
OUTPUT 17 DIV 5, " ", 17 MOD 5 // 3 2
Pythonlen("Computer")
"Computer"[0:4]
"hello".upper()
round(3.14159, 2)
import random; random.random()
17 // 5, 17 % 5

2210 WHILE uses DO; totalling & counting pattern

2210 only Run VB.NET · Java
CAIE pseudocode
DECLARE Total, Count, Num : INTEGER
Total 0
Count 0
INPUT Num
WHILE Num <> -1 DO
Total Total + Num
Count Count + 1
INPUT Num
ENDWHILE
OUTPUT "Total ", Total, " Count ", Count
Pythontotal = count = 0
num = int(input())
while num != -1:
    total += num
    count += 1
    num = int(input())

💡 Sentinel loops: INPUT before the loop and again at the end of the body.

2210 file handling

2210 only Run Run Python VB.NET · Java
CAIE pseudocode
DECLARE Line : STRING
OPENFILE "data.txt" FOR WRITE
WRITEFILE "data.txt", "Zak"
CLOSEFILE "data.txt"
OPENFILE "data.txt" FOR READ
READFILE "data.txt", Line
CLOSEFILE "data.txt"
OUTPUT Line
Pythonwith open("data.txt", "w") as f: f.write("Zak\n")
with open("data.txt") as f: line = f.readline().rstrip()
Enroll nowOnline classes