Variables, Constants and Data Types
Data Types
Every value stored in a program has a data type that tells the computer how to interpret the bits. Using the wrong data type causes programs to produce incorrect results or fail entirely.
AQA requires knowledge of five data types:
| Data type | What it stores | Example values | Python name |
|---|---|---|---|
| Integer | Whole numbers, positive or negative | -3, 0, 42 | int |
| Real | Numbers with a decimal point | 3.14, -0.5, 100.0 | float |
| Boolean | Logical true or false only | TRUE, FALSE | bool |
| Character | A single symbol | 'A', '7', '!' | str (length 1) |
| String | A sequence of zero or more characters | "hello", "AQA", "" | str |
Data type names vary by programming language. AQA pseudocode uses the terms above; Python uses
int,float,bool, andstr. Both sets of names appear in exam questions — know both.
Why data type matters: storing age as a string instead of an integer means arithmetic on it fails. Storing a price as an integer instead of a real loses the pence. Choosing the correct type is part of correct program design, not a cosmetic detail.
Variables and Constants
A variable is a named location in memory that stores a value which can change during the program's execution. A constant is a named location whose value is fixed at the start and never changed.
score ← 0 # variable — changes as the program runs
MAX_SCORE ← 100 # constant — set once, never modified
score = 0
MAX_SCORE = 100 # Python has no enforced constant keyword; use ALL_CAPS by convention
Why use named constants?
| Without a constant | With a constant |
|---|---|
IF score > 100 written in 12 places | IF score > MAX_SCORE written in 12 places |
| Changing the maximum requires 12 edits | Changing the maximum requires 1 edit |
| Easy to introduce inconsistency with a typo | Guaranteed consistency everywhere |
Meaningful identifier names are required by the spec. x and t1 are poor; studentScore and maxAttempts make code self-documenting. Examiners expect well-named identifiers in pseudocode answers — vague names like a or temp lose marks when the name is part of the mark scheme.
Assignment uses ← in AQA pseudocode and = in Python. The value on the right is evaluated first, then stored in the variable on the left: count ← count + 1 adds 1 to the current value and stores the result back.
Arithmetic Operators
Six arithmetic operators are required for the specification:
| Operator | Meaning | AQA pseudocode | Python | Example | Result |
|---|---|---|---|---|---|
| Addition | Add two values | + | + | 7 + 3 | 10 |
| Subtraction | Subtract right from left | - | - | 7 - 3 | 4 |
| Multiplication | Multiply two values | * | * | 7 * 3 | 21 |
| Real division | Divide, keeping decimal | / | / | 7 / 2 | 3.5 |
| Integer division | Quotient only, no remainder | DIV | // | 7 DIV 2 | 3 |
| Modulo | Remainder only, no quotient | MOD | % | 7 MOD 2 | 1 |
DIV and MOD are frequently tested. Two particularly useful patterns:
n MOD 2 = 0→nis even;n MOD 2 = 1→nis oddn DIV 10removes the rightmost digit:157 DIV 10 = 15n MOD 10extracts the rightmost digit:157 MOD 10 = 7
Worked example — A cinema has 150 seats in rows of 12. How many complete rows, and how many seats remain?
seats ← 150
rowSize ← 12
fullRows ← seats DIV rowSize # 12
leftOver ← seats MOD rowSize # 6
OUTPUT STR(fullRows) & " full rows, " & STR(leftOver) & " seats left"
Random number generation is also in §3.2.9: RANDOM_INT(a, b) in AQA pseudocode (Python: random.randint(a, b)) returns a random integer between a and b inclusive. Understanding the pseudo-random mechanism behind it is explicitly not required.
Relational and Boolean Operators
Relational operators compare two values and always produce a Boolean result:
| Operator meaning | AQA pseudocode | Python | Example |
|---|---|---|---|
| Equal to | = | == | 5 = 3 → FALSE |
| Not equal to | ≠ | != | 5 ≠ 3 → TRUE |
| Less than | < | < | 5 < 3 → FALSE |
| Greater than | > | > | 5 > 3 → TRUE |
| Less than or equal to | ≤ | <= | 5 ≤ 5 → TRUE |
| Greater than or equal to | ≥ | >= | 4 ≥ 5 → FALSE |
Boolean operators combine relational expressions into compound conditions:
| Operator | Meaning | Result |
|---|---|---|
AND | Both conditions must be TRUE | age ≥ 18 AND hasID = TRUE |
OR | At least one condition must be TRUE | colour = "red" OR colour = "blue" |
NOT | Inverts the Boolean value | NOT gameOver is TRUE when gameOver is FALSE |
Worked example — Award a merit if a score is between 60 and 79 inclusive:
IF score ≥ 60 AND score ≤ 79 THEN
OUTPUT "Merit"
ENDIF
Relational operators bind before Boolean operators: score > 60 AND score < 80 evaluates as (score > 60) AND (score < 80). Writing score > 60 AND 80 is a logic error — it does not work as intended.
Worth saving these ideas?
Turn what you've read into instant revision cards. Free to get started.
Input, Output and Type Conversion
Programs receive data from users with INPUT / USERINPUT and display results with OUTPUT / print().
OUTPUT "Enter your name: "
name ← USERINPUT
OUTPUT "Hello, " & name
name = input("Enter your name: ")
print("Hello, " + name)
input() in Python always returns a string, even when the user types a number. Arithmetic on an unconverted string causes a TypeError. Always convert before arithmetic.
Type conversion functions:
| Conversion | AQA pseudocode | Python |
|---|---|---|
| String → integer | INT(x) | int(x) |
| String → real | REAL(x) | float(x) |
| Integer → string | STR(x) | str(x) |
| Real → string | STR(x) | str(x) |
Worked example — Read two numbers and output their sum:
a = int(input("First number: "))
b = int(input("Second number: "))
print(a + b)
Without int(), "3" + "5" gives "35" (string concatenation), not 8 (addition). This is one of the most common runtime errors beginners make.
String Handling Operations
Strings are sequences of characters. AQA requires six string operations:
| Operation | Meaning | AQA pseudocode | Python |
|---|---|---|---|
| Length | Number of characters | LEN(str) | len(str) |
| Position | Index of first occurrence of a character | POSITION(str, char) | str.index(char) |
| Substring | Extract a portion | SUBSTRING(str, start, length) | str[start : start+length] |
| Concatenation | Join two strings | str1 & str2 | str1 + str2 |
| Char to code | ASCII value of a character | ASC(char) | ord(char) |
| Code to char | Character from an ASCII value | CHR(code) | chr(code) |
String indices start at 0 in AQA pseudocode — the first character is at position 0. This matches Python.
Worked example — Extract the area code from a postcode:
postcode ← "SW1A 2AA"
area ← SUBSTRING(postcode, 0, 3)
OUTPUT area # SW1
Worked example — Check whether two characters are adjacent in the alphabet:
diff ← ASC("C") - ASC("B") # 1 — adjacent
OUTPUT diff
diff ← ASC("E") - ASC("B") # 3 — not adjacent
OUTPUT diff
ASC("A") returns 65, ASC("Z") returns 90, ASC("a") returns 97. Upper and lower case have different codes.
Common Exam Mistakes
1. Treating input() output as a number without converting
input() in Python always returns a string. int(input(...)) converts it immediately. Forgetting this causes TypeError on arithmetic, or silent concatenation instead of addition.
2. Using / when integer division is required
7 / 2 gives 3.5. If the question requires a whole number result (e.g. how many complete groups), use DIV (// in Python) to get 3. Using real division and hoping the decimal part is zero is unreliable.
3. Confusing = assignment with = comparison in pseudocode
In AQA pseudocode, ← is assignment and = is comparison. Writing score = 5 inside an IF condition means "is score equal to 5?" — this is correct. Writing score = 5 as a standalone statement to assign a value is wrong; it should be score ← 5.
4. Boolean operator precedence errors
score > 60 AND 80 does not check whether score is between 60 and 80. It evaluates (score > 60) AND 80, which is a type error. The full condition must be: score > 60 AND score < 80.
5. Off-by-one in SUBSTRING
SUBSTRING("Hello", 0, 3) extracts 3 characters starting at index 0: "Hel". The second argument is the length, not the end index. Expecting "Hell" (4 characters) is an off-by-one error.
Generate revision on any topic you study
Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set — personalised to your level.
Lessons on anything
Structured, level-matched lessons on any topic you study
Practice quizzes
Find out what you actually know before the exam does
Flashcard sets
Lock in key concepts with instant revision cards
Ask Aica
Stuck on something? Get a clear explanation, any time
Merge Sort
Selection and Iteration
Related lessons
7 Slides
7 Slides
7 Slides