Mission 1 · Spec 3.2.1, 3.2.2 & 3.2.7
Data types, variables and constants
The five data types, how to store values in variables and constants, and how programs take input and give output.
- Starter 5 min
- Learn 10 min
- Lab 15 min
- Quiz 10 min
- Exam 10 min
"5" + "5"
In most programming languages, 5 + 5 gives 10. What do you think "5" + "5" gives? Why?
Reveal
"55". The quotes make them strings, and + joins strings together (concatenation). The same symbol does different things depending on the data type. That's why choosing the right type matters.
Key ideas
| Data type | Stores | Examples |
|---|---|---|
| Integer | Whole numbers | 42, -7, 0 |
| Real (float) | Numbers with a decimal part | 3.14, -0.5, 2.0 |
| Boolean | One of two values | True, False |
| Character | A single letter, digit or symbol | 'A', '7', '?' |
| String | A sequence of characters | 'Hello', '07700 900123' |
Variable
A named location in memory that stores a value which can change while the program runs.
score ← 0
score ← score + 10
Constant
A named value that cannot change while the program runs. Makes code easier to read and update in one place.
CONSTANT VAT ← 0.2
Assignment
Giving a variable a value. In AQA pseudocode the arrow ← is used.
Input and output
name ← USERINPUT reads from the keyboard. OUTPUT name displays on screen.
Use meaningful identifier names like totalScore, not x. It makes programs much easier to read and maintain.
Type sorter
Pick the most suitable data type for each item.Converting between types
Match each AQA pseudocode function to what it does.Exam-style questions
1. State the most suitable data type for: (a) the number of goals in a match (b) whether a match has finished (c) a team's name.
[3 marks]Mark scheme
- (a) Integer (1)
- (b) Boolean (1)
- (c) String (1)
2. Explain why a programmer might use a constant for the VAT rate instead of writing 0.2 throughout the program.
[2 marks]Mark scheme
- If the rate changes it only needs to be updated in one place (1)
- Fewer chances of errors / the value can't be changed accidentally while the program runs / the name makes the code easier to understand (1)
3. Explain why a phone number should be stored as a string, not an integer.
[2 marks]Mark scheme
- It may begin with 0, which would be lost as an integer (1)
- It may contain spaces / + signs / is not used in calculations (1)
TUTOR NOTES
- Misconception: "numbers should always be integers". Phone numbers and IDs are strings.
- Misconception: a constant is a variable you don't change. It is a value that can't be changed while running.
- Practical link: have the student write the same program in their exam language (Python, C# or VB.NET) alongside the pseudocode.
- Extension: what goes wrong with
age ← USERINPUTfollowed byage + 1?
Mission 2 · Spec 3.2.3 – 3.2.5
Operators
Arithmetic (including DIV and MOD), relational and Boolean operators.
- Starter 5 min
- Learn 10 min
- Lab 15 min
- Quiz 10 min
- Exam 10 min
Sharing sweets
23 sweets are shared equally between 5 people. How many does each person get? How many are left over?
Reveal
Each gets 4, with 3 left over. In code: 23 DIV 5 = 4 and 23 MOD 5 = 3. DIV is integer division, MOD is the remainder.
The operators
Arithmetic
+ - *
/ real division: 7 / 2 = 3.5
DIV integer division: 7 DIV 2 = 3
MOD remainder: 7 MOD 2 = 1
Relational
= equal to
≠ not equal to
< > ≤ ≥
These always give True or False.
Boolean
AND both must be True
OR at least one True
NOT flips True/False
Uses of MOD
n MOD 2 = 0 tests for even numbers. n MOD 10 gives the last digit. MOD also wraps things round, like a clock.
Expression blaster
How long a streak can you build?Exam-style questions
1. Give the result of: (a) 17 DIV 5 (b) 17 MOD 5 (c) 17 / 5
Mark scheme
- (a) 3 (1)
- (b) 2 (1)
- (c) 3.4 (1)
2. age ← 15 and member ← False. State whether each expression is True or False: (a) age ≥ 15 AND member (b) age < 18 OR member (c) NOT member
Mark scheme
- (a) False (1)
- (b) True (1)
- (c) True (1)
3. Write an expression that is True when the number stored in n is a multiple of 3.
Mark scheme
n MOD 3 = 0(1)
TUTOR NOTES
- Misconception: DIV rounds to the nearest whole number. It always rounds down (for positive numbers).
- Misconception: = in a condition is assignment. In AQA pseudocode ← assigns and = compares.
- Language link: in Python DIV is
//and MOD is%. - Extension: use DIV and MOD to split 137 minutes into hours and minutes.
Mission 3 · Spec 3.2.2
Selection and iteration
IF statements, and the three kinds of loop: count-controlled, condition at the start and condition at the end. Plus nesting.
- Starter 5 min
- Learn 10 min
- Lab 20 min
- Quiz 10 min
- Exam 10 min
Laps or until you're tired?
A PE teacher could say "run 5 laps" or "run until I blow the whistle". What is the difference in how you know when to stop?
Reveal
"5 laps" is definite: you know the number in advance, like a FOR loop. "Until the whistle" is indefinite: it depends on a condition, like a WHILE or REPEAT loop.
Key ideas
Selection
IF mark ≥ 70 THEN
OUTPUT 'Merit'
ELSE IF mark ≥ 50 THEN
OUTPUT 'Pass'
ELSE
OUTPUT 'Fail'
ENDIF
Definite iteration
Repeats a set number of times.
FOR i ← 1 TO 5
OUTPUT i
ENDFOR
Indefinite: condition at start
May run zero times.
WHILE guess ≠ 7
guess ← USERINPUT
ENDWHILE
Indefinite: condition at end
Always runs at least once.
REPEAT
guess ← USERINPUT
UNTIL guess = 7
Nesting means putting one construct inside another: an IF inside a loop, or a loop inside a loop.
Loop lab
Change the numbers and run each kind of loop.Definite or indefinite?
Exam-style questions
1. Explain the difference between a WHILE loop and a REPEAT … UNTIL loop.
[2 marks]Mark scheme
- WHILE checks its condition at the start, so the body may not run at all (1)
- REPEAT … UNTIL checks at the end, so the body always runs at least once (1)
2. Write an algorithm in pseudocode that outputs the even numbers from 2 to 20.
[3 marks]Mark scheme
- Uses a loop that runs from 2 (or 1) to 20 (1)
- Correctly selects / steps through only even numbers, e.g.
STEP 2orIF i MOD 2 = 0(1) - Outputs each number (1)
3. What is output by this code? FOR i ← 1 TO 3 / FOR j ← 1 TO 2 / OUTPUT i * j / ENDFOR / ENDFOR
Mark scheme
- 1, 2, 2, 4, 3, 6 (2)
- 1 mark for at least four values correct and in order
TUTOR NOTES
- Misconception: FOR i ← 1 TO 5 runs 4 times. AQA loops include both ends: 5 times.
- Misconception: using separate IFs where ELSE IF is needed, so more than one branch runs.
- Lab prompt: set the WHILE loop's start value to 0. Why does the lab warn about an infinite loop?
- Extension: rewrite a FOR loop as a WHILE loop. What extra lines do you need?
Mission 4 · Spec 3.2.6 & 3.2.8
Arrays, records and strings
Storing many values under one name, grouping related data, and pulling strings apart.
- Starter 5 min
- Learn 10 min
- Lab 20 min
- Quiz 10 min
- Exam 10 min
30 variables?
A teacher wants to store the test scores of 30 students. Would you make 30 variables called score1, score2 … score30? What problems would that cause?
Reveal
You couldn't loop through them, and adding a 31st student means changing the code. An array stores all 30 under one name: scores[0] to scores[29], and a loop can process them all.
Key ideas
1D array
A list of values of the same type under one identifier. Items are accessed by index, starting at 0.
names ← ['Ali', 'Bo', 'Cy']
OUTPUT names[1] # Bo
2D array
A table of values: one index for the row and one for the column.
grid[2][0]
Record
Groups related fields that can have different data types, such as a student's name (string), age (integer) and member status (Boolean).
RECORD Student
name : String
age : Integer
ENDRECORD
String handling
LEN(s)
POSITION(s, c)
SUBSTRING(start, end, s)
CHAR_TO_CODE(c) · CODE_TO_CHAR(n)
s + t (concatenation)
String workbench
Edit the string and try every operation.2D array explorer
Exam-style questions
1. word ← 'programming'. State the value of: (a) LEN(word) (b) SUBSTRING(0, 3, word) (c) POSITION(word, 'g')
Mark scheme
- (a) 11 (1)
- (b) 'prog' (1)
- (c) 3 (1)
2. Write an algorithm that outputs the total of all values in an array nums that contains 10 integers.
Mark scheme
- Initialises a total to 0 (1)
- Loops through indexes 0 to 9 adding each
nums[i]to the total (1) - Outputs the total after the loop (1)
3. Explain why a record would be used instead of an array to store details of a book (title, price, in stock).
[2 marks]Mark scheme
- The fields have different data types (string, real, Boolean) (1)
- An array can only store values of one data type / a record keeps related data together under named fields (1)
TUTOR NOTES
- Misconception: the first item is at index 1. AQA arrays and strings start at 0.
- Misconception: AQA SUBSTRING's end position is exclusive. It's inclusive: SUBSTRING(0, 3, …) gives four characters.
- Language link: Python slicing
s[0:4]is exclusive at the end, unlike AQA pseudocode. - Extension: write an algorithm that counts the vowels in a string.
Mission 5 · Spec 3.2.9 & 3.2.10
Subroutines and random numbers
Procedures and functions, parameters, return values and local variables, plus the structured approach. And how to make programs unpredictable.
- Starter 5 min
- Learn 10 min
- Lab 20 min
- Quiz 10 min
- Exam 10 min
Recipe steps
A recipe book says "make the white sauce (see page 12)" in five different recipes. Why doesn't it print the white sauce method five times?
Reveal
Write it once, use it many times. If the method changes, only page 12 needs updating. That's exactly what a subroutine does in a program.
Key ideas
Subroutine
A named, self-contained block of code that performs a specific task and can be called from elsewhere in the program.
Procedure vs function
A function returns a value to the code that called it. A procedure does not return a value.
Parameters
Variables listed in the subroutine's definition that receive values (arguments) when it is called.
Local variables
Exist only while the subroutine runs and can only be used inside it. This stops subroutines interfering with each other.
Why use subroutines?
- Code is written once and reused, so programs are shorter.
- Easier to test and debug each part separately.
- Different programmers can work on different subroutines.
- Easier to read and maintain. This is the structured approach: a modular program with clear interfaces (parameters and return values).
Inside a subroutine call
Step through a call and watch what happens in memory.Random number generator
Exam-style questions
1. Describe two advantages of using subroutines.
[4 marks]Mark scheme
- Code can be reused (1) so programs are shorter / less duplicated code (1)
- Subroutines can be tested independently (1) so errors are easier to find (1)
- Work can be shared between programmers (1) so development is faster (1)
- Easier to maintain (1) as a change is made in one place (1)
- Max 4: two advantages, each with an expansion
2. Explain the difference between a local variable and a global variable.
[2 marks]Mark scheme
- A local variable can only be accessed inside the subroutine where it is declared / exists only while it runs (1)
- A global variable can be accessed anywhere in the program (1)
3. Write a subroutine isAdult that takes an age as a parameter and returns True if the age is 18 or over, otherwise False.
Mark scheme
- Subroutine defined with an age parameter (1)
- Correct comparison,
age ≥ 18(1) - Returns True / False appropriately (1)
TUTOR NOTES
- Misconception: OUTPUT and RETURN do the same thing. OUTPUT shows the user; RETURN hands a value back to the program.
- Misconception: parameter and argument are identical. Parameter = in the definition; argument = the value passed in.
- Lab prompt: after the stars procedure ends, can the main program use
line? Why not? - Extension: write a dice-rolling game that uses a function to roll two dice and return the total.
Mission 6 · Spec 3.2.11
Robust and secure programs
Validation, authentication, choosing test data, and the difference between syntax and logic errors.
- Starter 5 min
- Learn 10 min
- Lab 20 min
- Quiz 10 min
- Exam 10 min
Break it
A program asks "How many tickets do you want (1 to 10)?". List every silly or unexpected thing a user could type in.
Reveal
Nothing at all, 0, -3, 11, 2.5, "two", "", a million… A robust program anticipates all of these and deals with them instead of crashing or doing something wrong.
Key ideas
Validation
Checking that input data is sensible and follows rules before it is used: presence, type, range, length and format checks.
Authentication
Checking a user's identity, e.g. with a username and password, before allowing access.
Syntax error
Breaks the rules of the language, so the program can't be translated and won't run. E.g. a missing bracket or misspelt keyword.
Logic error
The program runs but gives the wrong result. E.g. using < instead of ≤.
Test data
| Type | Meaning | For "age 11 to 18" |
|---|---|---|
| Normal | Typical data that should be accepted | 15 |
| Boundary | Values at the edge of what's allowed (either side) | 11, 18 (and 10, 19) |
| Erroneous | Data that should be rejected | 35, -2, "twelve" |
Validation gatekeeper
Try to sneak bad data past the checks.Choose the test data
A program accepts a percentage from 0 to 100.Bug hunt
This should output the average of 3 marks and say "Pass" for 50 or more. Find the three errors.Exam-style questions
1. A program asks for the number of players in a game, which must be from 2 to 6. Give one example each of normal, boundary and erroneous test data.
[3 marks]Mark scheme
- Normal: 3, 4 or 5 (1)
- Boundary: 2 or 6 (also accept 1 or 7) (1)
- Erroneous: e.g. 10, -1, "four" (1)
2. Write an algorithm that asks for a username and password and repeats until they match the stored values 'admin' and 'pa55word'.
Mark scheme
- Gets username and password from the user (1)
- Compares both with the stored values using AND (1)
- Uses a loop that repeats while they don't match (1)
- Outputs a suitable message on success / failure (1)
3. Explain the difference between a syntax error and a logic error.
[2 marks]Mark scheme
- A syntax error breaks the rules of the programming language, so the program will not run / translate (1)
- A logic error means the program runs but produces an incorrect / unexpected result (1)
TUTOR NOTES
- Misconception: validation makes data correct. It only makes it reasonable: "sam" passes, even if the name is Tom.
- Misconception: a program that crashes has a syntax error. A crash while running is not a syntax error.
- Bug hunt: ask which of the three errors a translator would catch (only the syntax error).
- Extension: why shouldn't a login screen say "wrong password" rather than "username or password incorrect"?