Spec & Goals 3 min
AQA Spec 3.2.2 · Variables and constants
By the end of this lesson you can:
- Define the terms variable and constant.
- Use assignment with
←to store a value. - Choose sensible identifier names for variables and constants.
Warm-Up 5 min
Last lesson we met the five data types. A program needs a place to keep those values — that place has a name.
Quick starter
In the line score ← 0, what does the arrow ← do?
Reveal the answer
It assigns — it stores the value 0 in a named store called score. We are about to give that store its proper name.
Key Concept — variables, constants and names 14 min
A variable is a named store whose value can change while the program runs.
A constant is a named value that cannot change once set. We declare it with CONSTANT.
Assignment
Assignment stores a value in a variable using the arrow ←. The name goes on the left, the value on the right.
| AQA pseudo-code | What it means |
|---|---|
age ← 15 | Store 15 in the variable age. |
age ← age + 1 | Change age to one more than it was. |
CONSTANT sst ← 0.06 | Declare a constant sst fixed at 0.06. |
Why use a constant?
- It makes the program clearer —
sstreads better than a bare0.06. - If the value ever changes, you edit it in one place.
- It prevents accidental changes to a value that must stay fixed.
Sensible identifier names
An identifier is the name of a variable or constant. Good names are clear and follow the rules.
- Describe the data:
totalPrice, notx. - No spaces; start with a letter; usually no symbols.
- Be consistent in style across the program.
Worked Example — a total with SST 12 min
Problem: read a price, add Malaysian SST at 6%, and output the total.
The tax rate never changes, so it is a constant. The price changes each run, so it is a variable.
AQA pseudo-code
CONSTANT sst ← 0.06 price ← STRING_TO_REAL(USERINPUT) tax ← price * sst total ← price + tax OUTPUT total
The same algorithm in Python
SST = 0.06 price = float(input("Enter the price: ")) tax = price * SST total = price + tax print(total)
For a price of 100, the tax is 6.0 and the total is 106.0.
Try It Yourself 12 min
Goal: Write AQA pseudo-code that stores your name in a variable called userName and outputs it.
Hint: use assignment with ←, then OUTPUT.
Goal: Declare a constant pi ← 3.142, read a radius, then output the area of a circle (pi * radius * radius).
Hint: use CONSTANT for pi and a variable for the radius.
Goal: A friend names a variable x for a shopping total. Suggest a better identifier and give one reason it is better.
📝 Exam Practice 10 min
Answer the way the examiner expects — the command word and the marks tell you how much to write.
Define the term variable.
Mark scheme
- A named store (in memory) whose value can change while the program runs (1).
Give one reason a programmer uses a constant rather than a variable.
Mark scheme
- Any one: the value cannot be changed by mistake / it makes code clearer / it is edited in one place (1).
State a suitable variable name to store the number of lives left in a game.
Mark scheme
- Any clear, descriptive name, e.g.
livesLeft/numLives(1).
Which one is a valid and sensible variable name?
A 2nd score B total price C highScore D x@1
Mark scheme
- C —
highScore(1). The others use a space, a leading digit or a symbol.
Recap & Key Terms 3 min
A variable is a named store whose value can change; a constant is a fixed named value. We store values with assignment (←) and name them with clear identifiers.
- Variable
- A named store in memory whose value can change while the program runs.
- Constant
- A named value, fixed when written, that cannot change while the program runs.
- Assignment
- Storing a value in a variable using the arrow
←. - Identifier
- The name a programmer gives to a variable, constant or subroutine.
Homework 1 min
Task (≤ 15 min): Write, in AQA pseudo-code, a program that declares a constant for the price of one ticket (RM12), reads how many tickets are wanted, and outputs the total cost.
Model answer
CONSTANT ticketPrice ← 12 quantity ← STRING_TO_INT(USERINPUT) total ← ticketPrice * quantity OUTPUT total
Award marks for: a constant for the price (1), input cast to an integer (1), correct total output (1).