- Describe what a variable is and explain how it stores data in memory
- Identify and describe the five data types: character, string, integer, real, boolean
- Choose the correct data type for a given piece of data
- Use Python assignment to store values and read equivalent SQA reference language
- Use Python arithmetic operators (+, −, *, /, **) in expressions
- Explain operator precedence (BODMAS) and apply brackets correctly
- Use Python string concatenation and convert numbers to strings for output
- I can define the term variable
- I can name all five N5 data types and give an example of each
- I can select the correct data type for a described piece of data
- I can write Python assignments and read DECLARE and SET statements in SQA reference language
- I can use all five arithmetic operators in expressions
- I can explain what BODMAS is and correct a BODMAS error in code
- I can join strings together using concatenation
Answer before the lesson begins. These check prior knowledge — it's fine if you're unsure.
1. Which of the following best describes pseudocode?
2. In a pseudocode design, what is the purpose of a refinement (e.g. step 2.1, 2.2)?
3. A program needs to repeat a set of steps exactly 5 times. Which type of operation should be used?
Key vocabulary
Variables, Data Types & Arithmetic
What is a variable?
Every useful program needs to store data — values typed by the user, results of calculations, or information the program needs to remember. A variable is a named storage location in the computer's memory that holds a single item of data.
Think of a variable like a labelled box: the label is the variable's name, and whatever is inside the box is its current value. When you put something new in the box, the old contents are permanently replaced — a variable can only hold one value at a time.
Variables must be given a meaningful name that describes what they store. A variable called score is immediately understandable; a variable called x is not. Meaningful names make code easier to read, maintain, and debug.
Declaring a variable
Some languages require a declaration to specify a variable’s name, data type and initial value. Python creates a variable when you first assign a value to it. Read the SQA reference-language declarations below; you do not write them.
SQA uses reference language in question papers. You need to be able to read it. You will never be asked to write it.
SQA reference language (read only)
DECLARE variableName AS DATATYPE INITIALLY startingValue
Examples:
SQA reference language (read only)
DECLARE score AS INTEGER INITIALLY 0 DECLARE playerName AS STRING INITIALLY "" DECLARE average AS REAL INITIALLY 0.0 DECLARE firstLetter AS CHARACTER INITIALLY "R" DECLARE gameOver AS BOOLEAN INITIALLY FALSE
Note that Python does not require variable declarations — it works out the type automatically when the variable is first assigned a value. This is called dynamic typing. Exam questions are written in SQA reference language, so you must be able to read it. When writing code answers, however, you may use any programming language; marks reward correct understanding and logic rather than exact reference-language syntax.
The five data types
A data type defines what kind of data a variable can store and what operations can be performed on it. There are five data types at N5:
1. Character
Stores a single letter, digit, or symbol. Internally the computer stores the ASCII code for that symbol.
SQA reference language (read only)
DECLARE firstInitial AS CHARACTER INITIALLY "R" SET firstInitial TO "R"
Examples of character values: "A", "7", "@", "!"
2. String
Stores a sequence of characters — essentially any piece of text. A phone number is stored as a string (not an integer) because it may start with 0, and you never do arithmetic with it.
SQA reference language (read only)
DECLARE username AS STRING INITIALLY "" SET username TO "coolcoder99"
Examples: "Edinburgh", "L3tme!n#@", "0131 252 5000"
3. Integer
Stores a positive or negative whole number. No decimal point is possible.
SQA reference language (read only)
DECLARE score AS INTEGER INITIALLY 0 SET score TO 42
Examples: 0, -6, 1000, -999. Key point: integers never appear in double quotes in code — quotes are for characters and strings only.
4. Real
Stores a positive or negative number that can include a decimal point. Python calls this type float; when identifying an N5 data type, use the course term real.
SQA reference language (read only)
DECLARE average AS REAL INITIALLY 0.0 SET average TO 7.35
Examples: 3.14, -0.5, 186.332
5. Boolean
Can only store two values: TRUE or FALSE. Booleans are commonly used as flags — to track whether something has happened yet.
SQA reference language (read only)
DECLARE score AS INTEGER INITIALLY 120
DECLARE gameOver AS BOOLEAN INITIALLY FALSE
IF score > 100 THEN
SET gameOver TO TRUE
END IF
Booleans connect directly to how all digital computers work at hardware level — everything ultimately comes down to 1s and 0s, true or false.
Choosing the right data type
Use this approach to choose a suitable data type:
- Is it a whole number you'll do arithmetic with? → Integer
- Is it a number with a decimal point? → Real
- Is it text, or a number you won't calculate with (like a postcode or phone number)? → String
- Is it a single letter or symbol? → Character
- Can it only ever be true or false? → Boolean
Assignment in Python
In Python, store data using assignment. The variable is created on its first assignment:
variableName = value
The computer reads the right-hand side first, works out the value, then stores the result in the variable on the left.
score = 0 playerName = "Maya" average = score / 10
Arithmetic operators in Python
When working with integers and real numbers, you can use arithmetic operators to perform calculations. The five operators at N5 are:
| Operator | Symbol | Example | Result |
|---|---|---|---|
| Addition | + | 12 + 5 | 17 |
| Subtraction | - | 12 - 5 | 7 |
| Multiplication | * | 12 * 5 | 60 |
| Division | / | 12 / 4 | 3.0 |
| Exponentiation | ** | 2 ** 8 | 256 |
Arithmetic operators are processed by the ALU (Arithmetic Logic Unit) inside the processor. The computer always evaluates the right-hand side of an assignment before storing the result.
length = 5.0 breadth = 3.0 price = 10.0 area = length * breadth total = price + (price * 0.2)
BODMAS — operator precedence
When an expression contains more than one operator, the order in which they are calculated matters. Python and SQA reference language follow the same mathematical rule: BODMAS.
| Letter | Stands for | Operations |
|---|---|---|
| B | Brackets | ( ) — always evaluated first |
| O | Orders | ** in Python; ^ in SQA reference language (exponentiation) |
| D | Division | / |
| M | Multiplication | * |
| A | Addition | + |
| S | Subtraction | - |
Multiplication and division have equal priority and are evaluated left to right; addition and subtraction also have equal priority. Multiplication and division happen before addition and subtraction unless brackets override the order.
Common BODMAS trap:
num1 = 6 num2 = 9 num3 = 12 average = num1 + num2 + num3 / 3 # WRONG: divides num3 first average = (num1 + num2 + num3) / 3 # CORRECT: adds all three first
String concatenation
Concatenation means joining two or more strings together to form a longer string. SQA reference language uses the & operator for concatenation:
SQA reference language (read only)
DECLARE firstName AS STRING INITIALLY "" DECLARE surname AS STRING INITIALLY "" SET firstName TO "Rohan" SET surname TO "Singh" SEND "Hello " & firstName & " " & surname & "!" TO DISPLAY
Output: Hello Rohan Singh!
Concatenation is also used to include variable values in output messages:
SQA reference language (read only)
SEND "Your score is " & score & " out of 100." TO DISPLAY
Use & to join each part of the output message in SQA reference-language SEND statements. Python uses + for string concatenation. Convert a number with str() before joining it to a string.
Worked examples
A program asks the user for their name and score (out of 50), then displays a personalised message.
Python implementation
playerName = input("Enter your name: ")
score = int(input("Enter your score (0-50): "))
percentage = (score / 50) * 100
print(playerName + " scored " + str(score) + " out of 50 (" + str(percentage) + "%)")
input() returns a string for the name; int() converts the score to an integer.str() converts the numbers to strings so Python can join them with +. With name Rohan and score 37, output is Rohan scored 37 out of 50 (74.0%).A program calculates the area of a circle using the formula area = π × r².
Python implementation
radius = float(input("Enter the radius: "))
pi = 3.14159
area = pi * radius ** 2
print("Area = " + str(area))
float() converts the input to a real number; pi is 3.14159.** squares the radius before multiplication by pi. SQA reference language uses ^ for the same operation.Area = 12.56636.A cinema booking system stores the following information. Select the correct data type for each item.
| Data item | Data type | Reason |
|---|---|---|
| Number of seats booked | Integer | A whole number — you cannot book half a seat |
| Ticket price | Real | Has a decimal point (e.g. £8.75) |
| Customer's full name | String | Text — a sequence of characters |
| Row letter (e.g. "G") | Character | A single letter only |
| Is the film sold out? | Boolean | Can only ever be TRUE or FALSE |
A program calculates the total cost of ordering cinema tickets. The user enters the number of adult tickets (£9.50 each) and child tickets (£6.00 each).
Answer the following:
- Write a Python assignment that gives
adultTicketsthe initial value 0. State the most appropriate N5 data type. - Write a Python assignment that calculates the total cost, storing it in a variable called
totalCost. AssumeadultTicketsandchildTicketshave already been given values. - Write a Python print statement that outputs:
Total cost: £followed by the value oftotalCost.
adultTickets = 0— Integer, because the number of tickets is always a whole number.totalCost = (adultTickets * 9.50) + (childTickets * 6.00)— Multiplication happens before addition even without these brackets. The result is a real number (Python float).print("Total cost: £" + str(totalCost))
float() to convert input to that type."EH14 4AP" contains letters and a space — it is impossible to store as an integer. If you would never do arithmetic with the value, it's a string.average = score1 + score2 + score3 / 3 divides only score3 by 3, then adds the others — giving the wrong answer. Use average = (score1 + score2 + score3) / 3.score = 10 stores the value 10 in score. In a condition, score == 10 tests whether they are equal. These look similar but do completely different things."Score: " + score raises a TypeError when score is an integer. Convert the number: "Score: " + str(score).When asked to "describe" a data type, the SQA expects you to state what kind of data it holds. A complete description for integer is: "stores a positive or negative whole number (no decimal point)". The word "number" alone does not distinguish integer from real; state whether decimal points are possible.
When asked to "choose a data type" for a given value, eliminate obviously wrong options first (is it text? → not integer/real/boolean), then check: does it have a decimal point? → real. Is it a whole number? → integer.
If a question shows a SEND statement and asks you to identify what it outputs, trace through any concatenated expressions carefully — the & operator joins each part left to right.
Questions 1–5 are auto-checked. Questions 6–10 are self-marked — write your answer, then reveal the model answer to check your work.
1. Which data type would be most appropriate to store a player's high score of 14,500? TYPE 1
2. A variable stores the value 3.14159. Which data type is this? TYPE 1
SQA reference language (read only)
3. Read the options: which line declares a string variable in SQA reference language? TYPE 1
SQA reference language (read only)
4. Read the SQA reference language: what is the output if name contains "Aisha" and score contains 37?SEND "Well done " & name & "! You scored " & score TO DISPLAY TYPE 1
SQA reference language (read only)
5. Read the SQA reference language: what value is assigned by SET result TO 2 + 3 * 4? TYPE 1
6. A hospital patient record system stores the following data. For each item, state the most appropriate data type and give a reason. TYPE 2
(a) Patient's date of birth stored as "12/04/1985"
(b) Number of appointments attended this year
(c) Whether the patient has been discharged
(d) Ward temperature reading of 36.8°C
(a) String — contains slashes and separators; you would never do arithmetic with a date of birth.
(b) Integer — a whole number count; you cannot attend a fraction of an appointment.
(c) Boolean — can only be TRUE (discharged) or FALSE (not yet discharged).
(d) Real — contains a decimal point (36.8°C).
7. A program calculates the volume of a cuboid (length × breadth × height). Write a complete Python program that inputs the three dimensions as real numbers, calculates the volume, and displays the result. Test with length 2.5, breadth 4 and height 3. TYPE 2
length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
height = float(input("Enter height: "))
volume = length * breadth * height
print("Volume = " + str(volume))
The dimensions are converted with float() because they may include decimal points. The test output is Volume = 30.0. Accept any correct Python solution that inputs the dimensions, multiplies them and displays the result.
SQA reference language (read only)
8. Read the SQA reference language below. Explain the error and describe how to correct the calculation in words:SET average TO score1 + score2 + score3 / 3 TYPE 2
Error: This is a BODMAS/operator precedence mistake. Division has higher precedence than addition, so score3 / 3 is evaluated first, then score1 and score2 are added to the result. This gives the wrong answer — it does not divide the sum of all three scores by 3.
Correction: Add all three scores inside brackets, then divide that sum by 3. Any clear explanation of this correction is accepted.
The brackets force the addition to happen before the division.
9. Write a complete Python program for the following scenario: A taxi company charges £2.50 per mile. The user enters the distance of their journey in miles (which may include a decimal point). The program should calculate and display the total fare, and show a message stating whether the fare is over £20. Your answer should include input converted with float(), calculation, output and an if/else statement. Test journeys of 4, 8 and 10.5 miles. TYPE 3
pricePerMile = 2.50
distance = float(input("Enter journey distance in miles: "))
fare = distance * pricePerMile
print("Distance: " + str(distance) + " miles")
print("Total fare: £" + str(fare))
if fare > 20:
print("This fare is over £20.")
else:
print("This fare is £20 or under.")
distance is real because the input may include a decimal point. Using pricePerMile as a named variable (rather than the literal 2.50) makes the code easier to maintain. Expected results: 4 miles → £10.0, £20 or under; 8 miles → £20.0, £20 or under; 10.5 miles → £26.25, over £20. Accept any correct Python solution with the same logic.
10. Read and trace the SQA reference language below step by step and state what is displayed on screen. Show your working. TYPE 3
SQA reference language (read only)
DECLARE a AS INTEGER INITIALLY 5 DECLARE b AS INTEGER INITIALLY 3 DECLARE c AS REAL INITIALLY 0.0 SET c TO (a + b) ^ 2 / 4 SEND "Result: " & c TO DISPLAY
Step 1: (a + b) = (5 + 3) = 8 — brackets first (B in BODMAS)
Step 2: 8 ^ 2 = 64 — exponentiation next (O in BODMAS)
Step 3: 64 / 4 = 16.0 — division (D in BODMAS)
Step 4: c is assigned 16.0 (stored as real)
Output: Result: 16.0
Suggested timing: 60 minutes. Warm up (5 min) → vocab + intro (10 min) → data types notes with examples (15 min) → worked examples walkthrough (10 min) → Now You Try (5 min) → task set (15 min).
Exam question mapping:
- Data types: Q1 (2024), Q5(a) (2024), Q7(a) (2025), Q12(b) (2025), Q2 and Q3 (2022), Q9(d) (2023) — useful data-type identification practice.
- Arithmetic / expressions: Q5(b) (2024), Q7(a) (2024), Q3(a) (2025), Q7(b) (2025) — commonly asks pupils to read and trace code or identify a bug.
- Concatenation: embedded in most "write code" questions.
Key misconception to address: Spend focused time on the BODMAS average trap (Q8). Distinguish the N5 data-type term real from Python’s float conversion.
Written tasks: Q7 and Q9 ask for Python implementation; check input conversion, arithmetic and output, plus the £20 boundary in Q9. Q8 asks pupils to read an error and explain the correction in words. Do not ask pupils to write reference language. Accept equivalent correct Python solutions.
Live demo suggestion: Type a short Python program live to show dynamic typing (no DECLARE needed), then contrast with the SQA reference language equivalent. Stress that pupils must be able to read SQA reference language, while written code answers may use any programming language and are marked for their logic. Also worth demoing what happens when BODMAS is wrong for an average calculation.
Extension question: A variable x is declared as integer. What happens if the user enters 3.7? What about "hello"? Discuss type errors and why strict typing in SQA reference language is useful for catching bugs early.
Assignment relevance: SDD Task 1 requires a working program with correct data structures and calculations. Choosing suitable data types supports correct implementation; Python creates variables through assignment. String concatenation appears in required output formatting.
SQA command words covered: "identify" (data type), "describe" (data type), "explain" (operator precedence error), "write" (code).