Track progress, take quizzes and save notes on this lesson.

Free forever · no card needed

Start free
Intermediate

Programming Fundamentals

4.1.1 Data types·arithmetic, relational and Boolean operations·string handling·random numbers·exception handling

Aligned to the AQA 7517 specification

Level
Intermediate
Reading time
7 min
Published
13 June 2026
Updated
1 July 2026
On this page
  1. 1.Data Types
  2. 2.Arithmetic and Comparison Operators
  3. 3.Boolean Operators
  4. 4.String Handling
  5. 5.Random Numbers
  6. 6.Exception Handling
  7. 7.Type Casting
  8. 8.Common Exam Mistakes

Key takeaways

  • Every value has a data type that determines how it is represented in memory and which operations are valid; AQA types include integer, real, Boolean, character, string, date/time, pointer/reference and record.
  • Real division `/` gives a real result (`7 / 2` = `3.5`), while integer division `DIV` discards the fraction (`7 DIV 2` = `3`) and `MOD` gives the remainder (`7 MOD 2` = `1`).
  • AQA pseudocode uses 1-based string indexing, so the first character is at position 1, and `SUBSTRING("Hello", 1, 3)` returns `"Hel"`.
  • A TRY block holds code that might fail; if an exception occurs control jumps to the EXCEPT block, and execution continues after ENDTRY.
  • `RANDOM_INT(a, b)` returns a random integer in the range a to b inclusive, so both endpoints can occur.

Data Types

Every value stored in a program has a data type that determines how it is represented in memory and what operations are valid on it. AQA specifies the following:

Data typeDescriptionExample
IntegerWhole number (positive, negative, zero)-5, 0, 42
Real (float)Number with a fractional part3.14, -0.5
BooleanTwo values onlyTrue, False
CharacterSingle symbol from a character set'A', '7', '?'
StringSequence of characters"Hello", "AQA"
Date/timeCalendar date or clock time2024-03-15
Pointer/referenceStores a memory address(address of variable)
RecordCollection of fields (mixed types)Student(name, age, grade)

Variables store values that can change during execution. Constants store fixed values — defined once, not reassigned. Using constants for fixed values (e.g. MAX_SIZE = 100) makes code easier to read and safer to maintain.

Arithmetic and Comparison Operators

Arithmetic operators produce a numeric result:

OperatorOperationExampleResult
+Addition7 + 310
-Subtraction7 - 34
*Multiplication7 * 321
/Real division7 / 23.5
DIVInteger division7 DIV 23
MODRemainder7 MOD 21
^Exponentiation2 ^ 8256

Comparison operators produce a Boolean result: <, <=, >, >=, =, .

Operator precedence (highest first): exponentiation → *, /, DIV, MOD+, - → comparisons. Use brackets to override: (2 + 3) * 4 = 20, not 2 + 3 * 4 = 14.

Boolean Operators

Boolean operators combine or negate Boolean values. They are essential for conditions in selection and iteration.

OperatorMeaningExampleResult
NOTNegationNOT TrueFalse
ANDBoth trueTrue AND FalseFalse
ORAt least one trueTrue OR FalseTrue
XORExactly one trueTrue XOR TrueFalse

(Extra context — not required by AQA 7517) Short-circuit evaluation: in A AND B, if A is False, B is not evaluated. In A OR B, if A is True, B is not evaluated. This can affect program behaviour when B has side effects.

Worked example — express "x is between 1 and 10 inclusive":

IF x >= 1 AND x <= 10 THEN
    OUTPUT "In range"
ENDIF

String Handling

Strings support a standard set of operations. These appear frequently in AQA exam questions:

OperationPseudocodeEffect
LengthLEN(s)Number of characters in s
PositionPOSITION(s, sub)Position of first occurrence of sub in s (1-indexed)
SubstringSUBSTRING(s, start, length)Extract part of string
Concatenations1 + s2Join two strings
Upper/lowercaseUPPER(s), LOWER(s)Convert case
Character codeASC(c)ASCII code of character c
Code to characterCHR(n)Character from code n
String to integerINT(s)Convert string "42" to integer 42
Integer to stringSTR(n)Convert integer 42 to string "42"

Worked example — extract the first three characters of a string:

name ← "Alexander"
initials ← SUBSTRING(name, 1, 3)  // "Ale" (1-indexed, 3 chars)
OUTPUT initials

Indexing convention: AQA pseudocode uses 1-based indexing — the first character is at position 1, not 0.

Worth saving these ideas?

Turn what you've read into instant revision cards. Free to get started.

Make flashcards

Random Numbers

Random number generation is useful for simulations, games, and sampling. In AQA pseudocode:

n ← RANDOM_INT(a, b)    // Random integer in range a to b inclusive

Worked example — simulate a six-sided die:

roll ← RANDOM_INT(1, 6)
OUTPUT "You rolled: " + STR(roll)

(Extra context — not required by AQA 7517) In most languages, the random number generator produces pseudo-random numbers — sequences that appear random but are generated by a deterministic algorithm seeded with an initial value. True randomness requires hardware (e.g. thermal noise sampling).

Exception Handling

An exception is an error condition that occurs at runtime — for example, dividing by zero, reading beyond the end of a file, or receiving unexpected input. Without handling, exceptions crash the program.

Try-except (try-catch) structure:

TRY
    x ← INT(userinput)
    result ← 100 / x
    OUTPUT result
EXCEPT
    OUTPUT "Invalid input or division by zero"
ENDTRY

The TRY block contains code that might fail. If an exception occurs, control jumps to the EXCEPT block. Execution continues after ENDTRY.

Exception handling should catch specific, anticipated errors — not suppress all errors indiscriminately. A broad catch-all can hide bugs.

Common runtime exceptions: division by zero, invalid type conversion, index out of bounds, file not found, null/None reference.

Type Casting

Type casting (type conversion) converts a value from one data type to another:

// String to integer
age_str ← "17"
age_int ← INT(age_str)       // 17 (as integer)

// Integer to string (for concatenation)
score ← 95
message ← "Your score: " + STR(score)   // "Your score: 95"

// String to real
price ← REAL("19.99")        // 19.99 (as real number)

Implicit vs explicit casting: some languages cast automatically (implicit), others require an explicit call. AQA pseudocode uses explicit conversion functions.

Pitfall: converting a non-numeric string to a number raises an exception — always validate input before casting, or use exception handling.

Common Exam Mistakes

1. Confusing integer division and real division

7 / 2 gives 3.5; 7 DIV 2 gives 3. Forgetting DIV causes type errors when an integer is required.

2. Misusing the MOD operator

MOD gives the remainder, not a fraction. 7 MOD 3 = 1 (not 2.33). Common use: test if a number is even with n MOD 2 = 0.

3. Using = for string comparison vs assignment

In AQA pseudocode, is assignment and = is comparison. Writing name = "Ali" in a condition is correct; writing name = "Ali" as a statement is wrong — it should be name ← "Ali".

4. 1-based vs 0-based string indexing

AQA pseudocode uses 1-based indexing. SUBSTRING("Hello", 1, 3) returns "Hel", not "ell". Python uses 0-based indexing — be aware when translating between pseudocode and code.

5. Forgetting that RANDOM_INT includes both endpoints

RANDOM_INT(1, 6) can return 1 and 6. Students sometimes assume the upper bound is excluded (as in Python's range()).

Key terms

Data type
A classification of a value that determines how it is represented in memory and what operations are valid on it.
Variable
A named store for a value that can change during program execution.
Constant
A named store for a fixed value defined once and not reassigned, making code easier to read and safer to maintain.
Arithmetic operator
An operator that produces a numeric result, such as `+`, `-`, `*`, `/`, `DIV`, `MOD` and `^`.
Comparison operator
An operator that produces a Boolean result, such as `<`, `<=`, `>`, `>=`, `=` and `≠`.
Boolean operator
An operator that combines or negates Boolean values: `NOT`, `AND`, `OR`, `XOR`.
Operator precedence
The order operators are evaluated: exponentiation, then `*`, `/`, `DIV`, `MOD`, then `+`, `-`, then comparisons, with brackets used to override.
Type casting
Converting a value from one data type to another, for example `INT("17")` converting a string to an integer.
Exception
An error condition that occurs at runtime, such as dividing by zero or reading beyond the end of a file, which crashes the program if unhandled.
RANDOM_INT(a, b)
A pseudocode function returning a random integer in the range a to b inclusive of both endpoints.
DIV
The integer division operator, which divides and discards any fractional part, so `7 DIV 2` is `3`.
MOD
The remainder operator, which gives the remainder after division, so `7 MOD 2` is `1`.

Frequently asked questions

`/` is real division and keeps the fractional part, so `7 / 2` gives `3.5`. `DIV` is integer division and discards the fraction, so `7 DIV 2` gives `3`. Forgetting `DIV` causes type errors when an integer is required.

AQA pseudocode uses 1-based indexing, so the first character is at position 1, not 0. For example `SUBSTRING("Hello", 1, 3)` returns `"Hel"`. Python uses 0-based indexing, so take care when translating between the two.

The TRY block contains code that might fail at runtime. If an exception such as division by zero or invalid type conversion occurs, control jumps to the EXCEPT block, and execution continues after ENDTRY. Handling should catch specific anticipated errors rather than suppress all errors.

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

Next

Subroutines and Recursion

Related lessons

6 min

6 min

Top students don’t revise more. They revise what counts.

Start revising free

Free to start. No card needed.