GCSEPaper 2Programming fundamentalsProgramming fundamentals
2.2.1

Programming fundamentals

Variables, operators, input and output plus sequence, selection and iteration.

Learning Objectives

  • 1Use variables, constants, operators, inputs, outputs and assignments
  • 2Understand the three basic programming constructs: sequence, selection and iteration
  • 3Recognise and use the required comparison, arithmetic and Boolean operators

Variables, constants and assignment

A variable is a named place to store data that can change while the program runs, like a score. A constant is a named value that never changes, like the value of pi. Assignment (using =) is how you store or update the value held in a variable.
A variable stores data that can change during a program's execution, e.g. name = "Aleks". A constant stores a value that stays fixed throughout the program, e.g. const vat = 0.2. Assignment uses = to set or update a variable's value, e.g. score = score + 10 adds 10 to the current value of score. Input receives data from the user, and output displays data to the user.
Distinguishing variables from constants is a required skill: a variable is expected to change value during execution, while a constant is fixed once declared and should not be reassigned. Global variables are declared once and accessible throughout the whole program, including inside sub-programs, this becomes especially relevant once functions and procedures are introduced.
Python· Variables, a constant, input and output
vat = 0.2
name = input("Enter your name: ")
score = 0
score = score + 10
print("Hello " + name)
OCR ERL· Variables, a constant, input and output
const vat = 0.2
name = input("Enter your name: ")
score = 0
score = score + 10
print("Hello " + name)

Sequence, selection and iteration

Every program is built from three basic constructs. Sequence means instructions run one after another, in order. Selection means the program makes a decision and branches, using IF/ELSE. Iteration means a block of instructions repeats, using WHILE or FOR.
The three constructs used to control the flow of any program are: sequence (instructions executed one after another, in the order they are written), selection (the program branches down different paths depending on a condition, using IF/ELSE IF/ELSE), and iteration (a block of code repeats, either a fixed number of times using a count-controlled FOR loop, or until/while a condition holds using a condition-controlled WHILE or DO UNTIL loop).
All programs, however complex, are built entirely from combinations of these three constructs, sequence, selection and iteration, often nested inside one another. Understanding each technique means being able to both use it correctly in a high-level language and identify it correctly when reading someone else's code.
SequenceRun in order, one after anotherSelectionIFTrueElseBranches based on a conditionIterationRepeatRepeats while/for a condition holds
Python· All three constructs together: sequence, a FOR loop (iteration), and an IF (selection)
total = 0
for i in range(1, 6):      # count-controlled iteration
    if i % 2 == 0:          # selection
        total = total + i
print(total)                # sequence: runs after the loop finishes
OCR ERL· All three constructs together: sequence, a FOR loop (iteration), and an IF (selection)
total = 0
for i = 1 to 5              // count-controlled iteration
    if i MOD 2 == 0 then    // selection
        total = total + i
    endif
next i
print(total)                 // sequence: runs after the loop finishes

Arithmetic operators

Arithmetic operators do maths: + add, - subtract, * multiply, / divide. Two less familiar ones are MOD, which gives the remainder of a division, and DIV, which gives the whole-number result of a division.
The required arithmetic operators are + (addition), - (subtraction), * (multiplication), / (division), MOD (modulo, the remainder after division), DIV (quotient, the whole number result of division), and ^ (exponentiation, to the power of). For example, 7 MOD 2 is 1 (the remainder), and 7 DIV 2 is 3 (the whole number of times 2 goes into 7).
MOD is commonly used to test whether a number is even or odd, e.g. number MOD 2 == 0 is true for even numbers, since an even number always divides by 2 with no remainder. DIV and MOD together can decompose a division into its whole and remainder parts, useful for tasks like converting a total number of seconds into minutes and seconds.
Python· MOD, DIV and exponentiation
number = 13
if number % 2 == 0:
    print("Even")
else:
    print("Odd")

total_seconds = 125
minutes = total_seconds // 60
seconds = total_seconds % 60

# Python uses ** for exponentiation, not ^
squared = 4 ** 2   # 16
OCR ERL· MOD, DIV and exponentiation
number = 13
if number MOD 2 == 0 then
    print("Even")
else
    print("Odd")
endif

totalSeconds = 125
minutes = totalSeconds DIV 60
seconds = totalSeconds MOD 60

squared = 4 ^ 2   // 16

Comparison operators

Comparison operators compare two values and give back True or False. The main ones are equal to (==), not equal to (!=), less than (<), greater than (>), less than or equal to (<=), and greater than or equal to (>=).
Comparison operators are used inside conditions (IF statements, WHILE loops) to compare two values and produce a Boolean (True/False) result: == equal to, != not equal to, < less than, <= less than or equal to, > greater than, >= greater than or equal to.
A single equals sign (=) means assignment; a double equals sign (==) means comparison, confusing these is a common syntax or logic error. When checking a value falls within an inclusive range (e.g. 1 to 100 inclusive), use >= and <=, not > and <, which would incorrectly exclude the boundary values themselves.

Boolean operators and combining conditions

Boolean operators work with True/False values. NOT flips a value (True becomes False). AND is only true if both conditions are true. OR is true if at least one condition is true.
AND returns True only if both of its conditions are true. OR returns True if at least one of its conditions is true. NOT reverses a Boolean value. These let you combine multiple conditions into one, e.g. if age >= 18 AND height >= 155 then only lets someone through if both conditions hold.
When two conditions are joined with AND or OR, each condition must independently and validly reference the variable being compared. Writing if PIN == "1234" OR "4321" then is a syntax error, since "4321" alone is not a valid comparison. The correct form repeats the variable: if PIN == "1234" OR PIN == "4321" then. This exact mistake, with AND or with OR, has been repeatedly identified by examiners across multiple series as a common error.
Python· Combining conditions correctly with AND / OR
age = int(input("Enter age: "))
height = int(input("Enter height (cm): "))
if age >= 18 and height >= 155:
    print("Entry allowed")

pin = input("Enter PIN: ")
if pin == "1234" or pin == "4321":
    print("Correct PIN")
OCR ERL· Combining conditions correctly with AND / OR
age = int(input("Enter age: "))
height = int(input("Enter height (cm): "))
if age >= 18 AND height >= 155 then
    print("Entry allowed")
endif

pin = input("Enter PIN: ")
if pin == "1234" OR pin == "4321" then
    print("Correct PIN")
endif

Exam Phrasing: Use These Exact Phrases

  • ✓A variable stores data that can change while the program runs; a constant stores a fixed value
  • ✓Sequence runs instructions in order, selection branches based on a condition, iteration repeats a block of code
  • ✓MOD returns the remainder of a division; DIV returns the whole number result
  • ✓Each condition joined with AND or OR must independently reference the variable being compared
  • 💡Remember MOD (remainder) and DIV (whole number quotient) are separate operators, and MOD is a fast way to test odd/even.
  • 💡When joining two conditions with AND or OR, always repeat the variable in full in both parts, e.g. pin == "1234" OR pin == "4321", not pin == "1234" OR "4321".
  • 💡Do not confuse = (assignment) with == (comparison), they do very different things.
  • 💡For an inclusive range (e.g. between 1 and 100 inclusive), use >= and <=, not > and <, which would wrongly exclude the boundary values.

Wrong:

if PIN == "1234" OR "4321" then

Right:

if PIN == "1234" OR PIN == "4321" then

Why it matters: The second part of the condition must also reference the variable, "4321" alone is not a valid, evaluable comparison.

Wrong:

x = 5 used to test if x equals 5

Right:

x == 5 used to test if x equals 5

Why it matters: A single = is assignment (sets the value); a double == is comparison (tests if two values are equal).

Wrong:

Renaming the variables a question gives you, e.g. writing word 1, wordone or world1 for word1

Right:

Use the exact variable names given in the question, spelled and spaced identically

Why it matters: OCR examiners were instructed not to allow renamed variables, even obvious typos. Free marks are lost to a stray space or a misspelling.

Wrong:

MOD and DIV do the same thing

Right:

MOD gives the remainder of a division; DIV gives the whole number result

Why it matters: 7 MOD 2 is 1 (the remainder); 7 DIV 2 is 3 (how many times 2 goes into 7).

Question:

Write an algorithm that asks the user to enter a number, then outputs whether the number is odd or even. [3]

Python· Model answer
number = int(input("Enter a number: "))
if number % 2 == 0:
    print("Even")
else:
    print("Odd")
OCR ERL· Model answer
number = int(input("Enter a number: "))
if number MOD 2 == 0 then
    print("Even")
else
    print("Odd")
endif

💡 Attempt this before revealing the answer, practice makes perfect!

Model Answer:

The algorithm takes a number as input, casts it to an integer, then uses MOD to check if dividing by 2 leaves a remainder. If number MOD 2 equals 0, the number is even; otherwise, it is odd.

Mark Scheme:

  • 1Correctly takes input from the user and stores it in a variable
  • 2Correctly uses the MOD operator to test divisibility by 2
  • 3Correctly outputs "Even" or "Odd" depending on the result, using an IF/ELSE structure

Tap a card to flip it. Use the arrow keys to move and space to flip.

Known 0 Still learning 0
1 / 12

Exam-style questions. Have a go, then reveal the mark scheme to check your answer.

1.Explain the difference between a variable and a constant.

[2]

2.State the value of 23 MOD 5 and the value of 23 DIV 5.

[2]

3.A student writes the condition "if colour == 'red' OR 'blue' then" to check if colour is red or blue. Identify the error and rewrite the condition correctly.

[2]

4.Name the three basic programming constructs, and give a one-sentence description of each.

[3]

5.Write an algorithm that asks the user for a number of total seconds, then outputs the equivalent number of whole minutes and remaining seconds.

[3]
Python· Model answer
total_seconds = int(input("Enter total seconds: "))
minutes = total_seconds // 60
seconds = total_seconds % 60
print(minutes, "minutes and", seconds, "seconds")
OCR ERL· Model answer
totalSeconds = int(input("Enter total seconds: "))
minutes = totalSeconds DIV 60
seconds = totalSeconds MOD 60
print(str(minutes) + " minutes and " + str(seconds) + " seconds")

6.Describe the three basic programming constructs, and explain why a program that validates a user's login needs all three.

[6]

The examiners' reports are the most useful and least read of the three: they say what candidates actually got wrong each year. All files are hosted by OCR.

Past-paper questions grouped by topic

The same OCR questions, sorted by topic rather than by year (via Physics & Maths Tutor).

2025
Paper 2

A common misconception affecting selection statements was joining two conditions with OR (or AND) without repeating the variable in the second condition, e.g. writing if PIN == "1234" OR "4321" then, which is not a valid comparison. The correct form is if PIN == "1234" OR PIN == "4321" then. This same error pattern was seen with AND earlier in the same paper, confirming it as a widespread, repeated misconception rather than a one-off mistake.

2024
Paper 2

The use of += as an alternative to writing out position = position + 5 in full was confirmed by examiners as an entirely acceptable, equivalent way of expressing assignment with arithmetic, credited the same as the longer form.