The vocabulary of Paper 2. Write it in Python on this page if you want — the exam may show ERL. Same ideas. Open 2.2.3 first if you already have loops.
2.2.1 Programming fundamentals
Variables and constants
A variable is a named store whose value can change. A constant is named but must not change (ERL: const VAT = 0.2). Named constants stop magic numbers spreading.
Assignment copies a value: score = 0. The right-hand side is worked out first.
Input / output
name = input("Name?")
print("Hi " + name)
Operators
- Arithmetic:
+ - * /and moduloMOD(%in Python) — remainder; DIV or//— integer division - Comparison:
== != < > <= >= - Boolean:
AND OR NOT
The three constructs
Every program is built from:
- Sequence — one statement after another
- Selection —
if / else if / else - Iteration — loops
Count-controlled: you know how many times (for i in range(10) / for i = 0 to 9).
Condition-controlled: until a condition fails (while lives > 0).
Nesting: a loop inside a loop, or an if inside a for. OCR added an explicit “use of nesting” note — they will ask.
for row = 1 to 3
for col = 1 to 3
print(row, col)
next col
next row
That prints nine pairs. Trace it once.
2.2.2 Data types
| Type | Holds | Example |
|---|---|---|
| Integer | Whole numbers | -3, 0, 42 |
| Real / float | Decimals | 3.14 |
| Boolean | True or False | True |
| Character | One symbol | 'A' |
| String | Text | "Lewis" |
Casting converts: int("7"), str(7), float("1.5"). Concatenating a number onto a string without casting is a classic Paper 2 trap.
Why types matter: 3 + 2 is 5; "3" + "2" is "32".
2.2.3 Additional programming techniques
Strings
Length, position, slicing, upper/lower, joining.
Python: s[0], s[1:4], len(s), s.upper(), s + t.
ERL-style: left(s, 3), right(s, 2), substring(s, 2, 3) — learn the idea: start and length.
Arrays (1D and 2D) and records
A 1D array is a numbered list of the same type. Index usually from 0 in Python; ERL questions will say.
A 2D array is a grid: grid[row][col]. Nested loops walk them.
A record groups different types under field names: pupil.name, pupil.year. In Python you might use a dict or a small class — the idea is the field names.
Files
Open, read, write, close. Always think: what if the file is missing? (That’s 2.3.)
file = open("scores.txt", "r")
line = file.readline()
file.close()
Write mode "w" overwrites. Append "a" adds.
Functions and procedures
- Procedure: a named block of code — does a job, may have parameters, typically no return
- Function: returns a value
Parameters are the inputs in the definition; arguments are the values you pass. Scope: a variable created inside a function is local — invisible outside.
function add(a, b)
return a + b
endfunction
Passing an array still needs care: in Python the list is mutable; in ERL, follow the question.
SQL
A tiny language for tables.
SELECT name, year FROM pupils WHERE year = 9
- SELECT columns (
*means all) - FROM table
- WHERE filter
- Sometimes ORDER BY
SQL injection is 1.4 — here you only need to read and write simple queries.
Random numbers
random(1, 6) in ERL, random.randint(1, 6) in Python. Games and simulations. Seed is beyond GCSE unless they mention it.
The programming lesson repeats these in longer Python katas. Use either page; neither is locked behind the other.