Intermediate

Programming Fundamentals

AicademyAicademy
·A-Level Computer Science·AQA 7517·7 min
4.1.1 Data types·arithmetic, relational and Boolean operations·string handling·random numbers·exception handling

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.

Something not quite clicking?

Ask Aica to explain any part of this differently. Free, takes 30 seconds.

Ask Aica

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()).

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

8 Slides

Lesson

Subroutines and Recursion

A-Level Computer Science · AQA 7517

10 hours ago

7 Slides

Lesson

Object-Oriented Programming

A-Level Computer Science · AQA 7517

10 hours ago