You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers the fundamental building blocks of every program — variables, constants, and data types. Understanding these concepts is essential for GCSE Computer Science (AQA 3.2 / OCR J277 2.2) and forms the foundation of all programming topics.
A variable is a named location in memory that stores a value which can change during the execution of a program. Think of it as a labelled box — the label is the variable name, and the contents of the box is the value.
In pseudocode (AQA style):
name ← "Alice"
age ← 16
score ← 0
In Python:
name = "Alice"
age = 16
score = 0
The assignment operator (← in pseudocode, = in Python) stores the value on the right into the variable on the left. Variables can be reassigned at any time:
score = 10
score = score + 5 # score is now 15
totalScore not x).totalScore) or snake_case (total_score).if, while, print.Exam Tip: The examiner wants you to use meaningful identifiers. A variable called
twill often lose you marks compared withtemperature.
A constant is a named value that is set once and cannot be changed during the execution of the program. Constants make code easier to read and maintain.
In pseudocode:
CONST VAT_RATE ← 0.20
CONST PI ← 3.14159
In Python (by convention — Python does not enforce constants):
VAT_RATE = 0.20
PI = 3.14159
| Benefit | Explanation |
|---|---|
| Readability | VAT_RATE is clearer than 0.20 scattered through code |
| Maintainability | Change the value in one place and it updates everywhere |
| Error prevention | Prevents accidental modification of important values |
Exam Tip: If a question asks the difference between a variable and a constant, state that a variable's value can change during execution whereas a constant's value is fixed once assigned.
flowchart LR
V[Value e.g. 16] -->|stored in| B["Memory location<br/>labelled 'age'"]
B -->|read by| U[age + 1]
U -->|reassigned| B
style B fill:#e0f2fe,stroke:#0284c7
The arrow in age ← 16 (or age = 16 in Python) represents the flow of the value into the named memory location. Reading age later retrieves the most recently stored value.
A data type defines the kind of value a variable can hold. The five data types you must know for GCSE are:
| Data Type | Description | Example |
|---|---|---|
| Integer | A whole number (positive or negative) | 42, -7, 0 |
| Real / Float | A number with a decimal point | 3.14, -0.5, 100.0 |
| Boolean | A value that is either True or False | True, False |
| Character | A single letter, digit, or symbol | 'A', '7', '!' |
| String | A sequence of characters | "Hello", "GCSE2025" |
An integer has no fractional part: 5, -12, 0. A real (also called a float) has a decimal point: 5.0, -12.75. This distinction matters because integers use less memory and arithmetic with them is faster.
A Boolean can only hold one of two values: True or False. Booleans are central to selection and iteration because conditions evaluate to a Boolean result.
is_logged_in = True
has_passed = score >= 50 # evaluates to True or False
A character (char) is a single symbol, whereas a string is zero or more characters in sequence. In Python, there is no separate char type — a single character is simply a string of length 1.
letter = 'A' # character (string of length 1 in Python)
greeting = "Hello" # string of length 5
Sometimes you need to convert between data types. This is called casting.
age = int("16") # string → integer
price = float("9.99") # string → real
label = str(42) # integer → string
In pseudocode:
age ← INT("16")
price ← REAL("9.99")
label ← STRING(42)
Casting is essential when reading user input, because input() in Python always returns a string:
age = int(input("Enter your age: "))
Exam Tip: A very common error in exam pseudocode answers is forgetting to cast the input to an integer before comparing it with a number. Always show the cast explicitly.
The following Python program shows variables and constants working together. Note the naming convention: the constant VAT_RATE is written in upper case to signal that its value must not be reassigned.
VAT_RATE = 0.20
DISCOUNT_THRESHOLD = 50.00
item_name = input("Item name: ")
net_price = float(input("Net price (GBP): "))
if net_price >= DISCOUNT_THRESHOLD:
net_price = net_price * 0.95 # 5% loyalty discount
vat = net_price * VAT_RATE
gross = net_price + vat
print(f"Item: {item_name}")
print(f"Net: GBP {net_price:.2f}")
print(f"VAT: GBP {vat:.2f}")
print(f"Gross: GBP {gross:.2f}")
Trace for input "Keyboard" and 60:
| Step | Variable | Value | Notes |
|---|---|---|---|
| 1 | VAT_RATE | 0.20 | Declared as constant |
| 2 | DISCOUNT_THRESHOLD | 50.00 | Declared as constant |
| 3 | item_name | "Keyboard" | String input |
| 4 | net_price | 60.0 | Cast from string to real |
| 5 | net_price | 57.0 | Discount applied (60 * 0.95) |
| 6 | vat | 11.4 | 57 * 0.20 |
| 7 | gross | 68.4 | 57 + 11.4 |
Expected output:
Item: Keyboard
Net: GBP 57.00
VAT: GBP 11.40
Gross: GBP 68.40
Boolean variables are used to record the state of something that can only be one of two values. Here, a flag records whether a pupil is eligible for free school meals.
household_income = float(input("Annual household income: "))
INCOME_THRESHOLD = 7400.00
is_eligible = household_income < INCOME_THRESHOLD
print(f"Eligible for FSM: {is_eligible}")
If the household income is 6500, the Boolean expression 6500 < 7400 evaluates to True, and that value is stored directly in is_eligible without needing an IF statement.
CONST MAX_CHARACTERS ← 160
OUTPUT "Enter message:"
message ← USERINPUT
chars_used ← LEN(message)
chars_left ← MAX_CHARACTERS - chars_used
OUTPUT "Characters used: ", chars_used
OUTPUT "Characters left: ", chars_left
If the user types "Hello", chars_used becomes 5 and chars_left becomes 155.
In weakly-typed languages like Python, a variable can hold different types across its lifetime, but you should avoid this because it reduces clarity.
score = 0 # integer
score = score + 10 # still integer (10)
score = score / 3 # now a real (3.33...)
A statically-typed language such as Java would reject this because the variable's type is fixed at declaration.
Imagine a program that references 0.20 in twenty different places. If the VAT rate changes to 0.175, you must find and update every occurrence, risking missed changes. With a constant, only one line changes:
VAT_RATE = 0.175 # single source of truth
Exam-style question (4 marks): Explain the difference between a variable and a constant, and describe one benefit of using a constant.
Grades 3–4 response: A variable can change but a constant cannot. Constants are good because they do not change by accident.
Grades 5–6 response: A variable stores a value that can change during program execution, whereas a constant stores a value that is fixed after it is first set. Using a constant makes code easier to read because the name describes the value's meaning.
Grades 7–9 response: A variable is a named memory location whose contents may be reassigned during execution, while a constant is a named value bound at initialisation and protected against further assignment. Using a constant improves maintainability (a single update site for a fixed quantity such as VAT_RATE) and readability (the identifier communicates semantic intent rather than a magic number). It also supports defensive programming because the compiler or interpreter can raise an error if code attempts to reassign the constant, reducing the risk of silent logic faults.
CONST REORDER_LEVEL = 10
stock = 25
daily_sales = 6
received = 2
stock = stock - daily_sales
stock = stock + received
reorder_needed = stock < REORDER_LEVEL
print(f"Closing stock: {stock}")
print(f"Reorder needed: {reorder_needed}")
Step-by-step trace:
| Step | Statement | stock | reorder_needed | Notes |
|---|---|---|---|---|
| 1 | stock = 25 | 25 | — | Integer variable declared |
| 2 | daily_sales = 6 | 25 | — | Another integer |
| 3 | stock = stock - daily_sales | 19 | — | Reassignment |
| 4 | stock = stock + received | 21 | — | Reassignment |
| 5 | reorder_needed = stock < REORDER_LEVEL | 21 | False | Boolean from comparison |
Expected output:
Closing stock: 21
Reorder needed: False
Although Python transparently handles large integers, other languages impose fixed ranges. You should be aware of the following typical ranges in a 32-bit signed representation: -2,147,483,648 to +2,147,483,647. Real numbers use floating-point representation with a trade-off between range and precision. This is why comparing real numbers for exact equality is discouraged; instead, check that the absolute difference is within a small tolerance.
A camelCase identifier starts with a lower-case letter and capitalises subsequent words (totalScore). A snake_case identifier uses underscores (total_score) and is conventional in Python. Constants use UPPER_SNAKE_CASE (VAT_RATE). Using a consistent style is part of good programming practice and is rewarded in the exam rubric under "use of meaningful identifiers and consistent style".
paper_1 = int(input("Paper 1: "))
paper_2 = int(input("Paper 2: "))
paper_3 = int(input("Paper 3: "))
total_marks = paper_1 + paper_2 + paper_3
mean_mark = total_marks / 3
print(f"Total: {total_marks}")
print(f"Mean: {mean_mark:.1f}")
For inputs 45, 60, 72, the variables take the values shown below.
| Variable | Value | Type |
|---|---|---|
paper_1 | 45 | integer |
paper_2 | 60 | integer |
paper_3 | 72 | integer |
total_marks | 177 | integer |
mean_mark | 59.0 | real |
Note how total_marks / 3 yields a real number (59.0) even though all operands are integers — in Python 3, the / operator always produces a real-typed result. If integer division is required, use //.
Some languages require you to declare a variable's type before use:
DECLARE counter AS INTEGER
DECLARE name AS STRING
DECLARE score AS REAL
AQA pseudocode does not require explicit declarations, but the exam mark scheme awards credit for clear, correctly-typed use of variables regardless of whether declarations are shown.
CATEGORY_UNDER = "Underweight"
CATEGORY_NORMAL = "Healthy"
CATEGORY_OVER = "Overweight"
CATEGORY_OBESE = "Obese"
weight_kg = float(input("Weight (kg): "))
height_m = float(input("Height (m): "))
bmi = weight_kg / (height_m ** 2)
if bmi < 18.5:
category = CATEGORY_UNDER
elif bmi < 25:
category = CATEGORY_NORMAL
elif bmi < 30:
category = CATEGORY_OVER
else:
category = CATEGORY_OBESE
print(f"BMI: {bmi:.1f} ({category})")
This example uses constants (strings), reads two real-valued inputs, performs real arithmetic and displays a formatted result — revisiting every variable/constant/data-type concept in a single program.
AQA alignment: This content is aligned with AQA GCSE Computer Science (8525) specification — specifically section 3.2 Programming (3.2.1–3.2.12 covering data types, constants/variables, arithmetic/relational/Boolean operations, selection, iteration, arrays, records, file handling, string handling, SQL, arrays of records, subroutines/functions/procedures, structured programming, robust and secure programming, classification of languages). Assessed on Paper 1 and Paper 2.