📄 Paper 1 · 4.1 Fundamentals of Programming
⭐ Pro
4.1.1d String Handling & Random Number Generation
AQA 7517 · A-Level Computer Science · ~15 min read

String Handling

AQA 7517 requires you to be able to use and describe the following string operations in pseudocode:

OperationAQA PseudocodeExampleResult
LengthLEN(str)LEN("Hello")5
SubstringSUBSTRING(str, start, length)SUBSTRING("Hello World", 6, 5)"World"
UppercaseUPPER(str)UPPER("hello")"HELLO"
LowercaseLOWER(str)LOWER("HELLO")"hello"
Concatenation&"Hello" & " " & "World""Hello World"
Char to codeASC(char)ASC("A")65
Code to charCHR(code)CHR(65)"A"

String Indexing

In AQA pseudocode, strings are typically 1-indexed — the first character has index 1. However, the exact indexing may vary and AQA exam questions will clarify when needed.

Example: For str ← "Computing", SUBSTRING(str, 1, 4)"Comp"

Note: SUBSTRING(str, start, length) extracts length characters starting at position start.

Practical String Operations

Reversing a string — iterating backwards using SUBSTRING:

Checking for palindrome — comparing original with reversed version

Extracting digits — using SUBSTRING and checking if character is numeric

Converting case — using ASC/CHR arithmetic: uppercase letters A–Z are codes 65–90; lowercase a–z are 97–122. To convert: CHR(ASC(ch) + 32) converts uppercase to lowercase.

String Concatenation

The & operator joins two strings together:

firstName & " " & surname — joins with a space between them

Note: when concatenating strings with numbers, you must convert numbers to string first (language-dependent).

Random Number Generation

AQA 7517 requires you to use RANDOM to generate random numbers in pseudocode:

RANDOM(lower, upper) — returns a random integer between lower and upper inclusive

Examples:

  • RANDOM(1, 6) — simulates a dice roll (1, 2, 3, 4, 5, or 6)
  • RANDOM(0, 1) — returns 0 or 1 (simulates a coin flip)
  • RANDOM(1, 52) — selects a random card from a deck

Pseudo-Random Numbers

Computer-generated "random" numbers are actually pseudo-random — produced by a deterministic algorithm (called a PRNG — pseudo-random number generator) seeded with a starting value. The same seed always produces the same sequence. For truly random behaviour, seeds are taken from unpredictable sources (system time, hardware noise).

Exam tip: SUBSTRING indexing is frequently tested — make sure you know that it takes (string, start_position, length_of_substring), not (start, end). Also know that CHR and ASC are inverses of each other: CHR(ASC('A') + 1) = 'B'. Random number exam questions often ask you to write code to simulate a dice or pick from a range — use RANDOM(min, max).
⚠️ Common Mistakes
  • Confusing SUBSTRING parameters — the third parameter is length, not end position
  • Using Python string methods (.upper()) instead of AQA pseudocode functions (UPPER(str))
  • Thinking RANDOM is truly random — it's pseudo-random (deterministic but appears random)
  • Forgetting that concatenation in AQA uses & not + (+ is for numbers)
  • Getting ASCII codes wrong — 'A' = 65, 'a' = 97, '0' = 48
Video coming soon
Click through the slides at your own pace. Use arrow keys or click to advance.
Click slide or press arrow keys to navigate

Worksheet — 4.1.1d String Handling & Random Numbers

8 questions · instantly marked · AQA 7517 standard

Q1State the result of: SUBSTRING("Computer Science", 9, 7)[1]
✅ Mark scheme
Mark scheme
"Science" [1] — starting at position 9, length 7.
Q2Explain what ASC("A") returns and how CHR is related to ASC.[2]
✅ Mark scheme
Mark scheme
ASC("A") returns 65 [1] — the ASCII/Unicode character code for 'A'. CHR is the inverse of ASC — CHR(65) returns "A" [1].
Q3Write AQA pseudocode to generate a random number to simulate rolling two six-sided dice and storing the total.[3]
✅ Mark scheme
Mark scheme
die1 ← RANDOM(1, 6) [1]; die2 ← RANDOM(1, 6) [1]; total ← die1 + die2 [1].
Q4State the result of: UPPER(SUBSTRING("algorithm", 1, 4))[1]
✅ Mark scheme
Mark scheme
"ALGO" [1] — SUBSTRING("algorithm",1,4) gives "algo"; UPPER converts to "ALGO".
Q5Explain why computer-generated random numbers are described as "pseudo-random".[2]
✅ Mark scheme
Mark scheme
They are generated by a deterministic algorithm [1] — the same starting seed always produces the same sequence, so they are not truly random; they only appear random [1].
Q6Write AQA pseudocode using the & operator to build a greeting: given firstName = "Ada" and lastName = "Lovelace", construct "Hello, Ada Lovelace!"[2]
✅ Mark scheme
Mark scheme
greeting ← "Hello, " & firstName & " " & lastName & "!" [2] — award [1] for correct use of & to join strings; [1] for correctly including the space between names.
Q7What is LEN("AQA A-Level")? Show how you would use LEN to iterate through each character of a string.[3]
✅ Mark scheme
Mark scheme
LEN("AQA A-Level") = 11 [1]; FOR i ← 1 TO LEN(str) [1]; OUTPUT SUBSTRING(str, i, 1) / or equivalent character access [1].
Q8A programmer uses CHR(ASC("a") - 32) to convert lowercase to uppercase. Explain why this works and state what CHR(ASC("m") - 32) produces.[3]
✅ Mark scheme
Mark scheme
Uppercase letters A–Z have ASCII codes 65–90 and lowercase a–z have codes 97–122 [1]; the difference is always 32 [1]; so ASC("m") = 109, 109 - 32 = 77, CHR(77) = "M" [1].
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 12
Click to reveal definition
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — String Handling

10 questions · 10 minutes

← 4.1.1c Operations
4 of 70 · AQA 7517
4.1.1e Exception Handling →