Intermediate

Writing Exam-Style Programs

AicademyAicademy
·GCSE Computer Science·AQA 8525·6 min
Support lesson — programming skills (not a separate AQA spec section)

Why Integration Is Hard

The programming spec is taught topic by topic — variables, then selection, then iteration, then arrays, then subroutines. But Paper 1 exam questions do not arrive topic by topic. A question might ask you to write a program that uses all of those things together, in a single coherent solution.

This lesson does not introduce new programming concepts. It shows you how to pull everything you already know into a complete program — the way the exam requires you to.

Step 1: Plan Before You Write

The biggest Paper 1 mistake is writing code immediately. Students who plan first write cleaner, more complete programs and make fewer errors.

Always start with inputs, processing, outputs (IPO):

Scenario: Write a program that asks a user to enter 5 quiz scores (each between 0 and 10), validates each score, stores them, calculates the average, and tells the user whether they passed (average ≥ 6) or failed.

ComponentDetail
Inputs5 quiz scores, each entered by the user
ProcessingValidate each score (range 0–10); store in array; sum all scores; calculate average
OutputEach invalid score rejected with a message; final average; "Pass" or "Fail"

What programming constructs do I need?

  • Array to store 5 scores
  • FOR loop to collect 5 inputs
  • WHILE loop (inside FOR) for validation
  • Accumulator to total the scores
  • IF/ELSE for pass/fail decision
  • FUNCTION to keep validation reusable

Planning this before writing means you will not reach the end and realise you forgot validation, or used the wrong loop type.

Step 2: Write the Program

With the plan in hand, build the solution piece by piece.

Pseudocode:

FUNCTION getValidScore()
    OUTPUT "Enter score (0-10): "
    score ← INT(USERINPUT)
    WHILE score < 0 OR score > 10 DO
        OUTPUT "Invalid. Enter a score between 0 and 10: "
        score ← INT(USERINPUT)
    ENDWHILE
    RETURN score
ENDFUNCTION

SUBROUTINE runQuiz()
    scores ← [0, 0, 0, 0, 0]
    total ← 0

    FOR i ← 0 TO 4
        scores[i] ← getValidScore()
        total ← total + scores[i]
    NEXT i

    average ← total / 5

    OUTPUT "Your average score is: " & STR(average)

    IF average ≥ 6 THEN
        OUTPUT "Pass"
    ELSE
        OUTPUT "Fail"
    ENDIF
ENDSUBROUTINE

runQuiz()

Python equivalent:

def get_valid_score():
    score = int(input("Enter score (0-10): "))
    while score < 0 or score > 10:
        print("Invalid. Enter a score between 0 and 10.")
        score = int(input("Enter score (0-10): "))
    return score

def run_quiz():
    scores = [0] * 5
    total = 0

    for i in range(5):
        scores[i] = get_valid_score()
        total += scores[i]

    average = total / 5
    print(f"Your average score is: {average}")

    if average >= 6:
        print("Pass")
    else:
        print("Fail")

run_quiz()

Step 3: Trace and Check

Once written, verify the program with a trace table. Use a test case that exercises the validation (an invalid input followed by a valid one) and checks the pass/fail branch.

Test: inputs are 10, 8, 7, 6, 9 — all valid, average = 8.0, expect Pass.

iscore enteredvalid?scores[i]total after
0101010
18818
27725
36631
49940

average = 40 / 5 = 8.0 → 8.0 ≥ 6 → Output: "Pass" ✓

Test: one invalid input — user enters 15, then 8.

AttemptInputCondition: 15 < 0 OR 15 > 10Action
115TRUEReject, ask again
28FALSEAccept, exit WHILE

score returned = 8 ✓

Want more lessons like this one?

Generate lessons on anything you study. Free account, no card needed.

Start generating

The Most Common Paper 1 Errors

These errors appear in student answers repeatedly. Check your program against every item before you stop writing.

1. Uninitialised variables

# Wrong — total has no starting value
FOR i ← 0 TO 4
    total ← total + scores[i]
NEXT i
# Correct
total ← 0
FOR i ← 0 TO 4
    total ← total + scores[i]
NEXT i

Using a variable before assigning it a value is a logic error that produces unpredictable results.

2. Missing ENDIF or ENDWHILE

# Wrong
IF average ≥ 6 THEN
    OUTPUT "Pass"
ELSE
    OUTPUT "Fail"
# Missing ENDIF — syntax error, program cannot run

Every IF needs ENDIF. Every WHILE needs ENDWHILE. Every FOR needs NEXT. Check these before finishing.

3. Wrong loop type

  • FOR — use when you know the exact number of iterations in advance (e.g. "collect 5 scores")
  • WHILE — use when you repeat until a condition changes (e.g. "keep asking until valid")

Using a FOR loop for validation forces a fixed number of attempts. Using a WHILE loop to collect exactly 5 scores makes the count harder to control. Match the loop type to the problem.

4. Array index errors

AQA pseudocode arrays are zero-indexed by convention in most contexts. A 5-element array uses indices 0 to 4. A FOR loop to fill it should run FOR i ← 0 TO 4, not 1 TO 5.

5. No validation on user input

If the question describes a range or constraint on input, validate it. An unvalidated input that accepts any value — including impossible ones — is an incomplete answer for any question that asks for a "robust" or "secure" program.

6. Using SUBROUTINE when a value needs to be returned

A SUBROUTINE performs actions but does not return a value. A FUNCTION calculates and returns a value with RETURN. If your code needs to use the result of a called block elsewhere, it must be a FUNCTION.

# Wrong — SUBROUTINE cannot be used to return a value
SUBROUTINE getValidScore()
    ...
    RETURN score   # invalid in a SUBROUTINE
ENDSUBROUTINE

# Correct
FUNCTION getValidScore()
    ...
    RETURN score
ENDFUNCTION

7. Vague identifier names

x, a, temp tell the examiner nothing. Use names that reflect the variable's purpose: score, total, average, userName. Clear identifiers also reduce your own mistakes.

Adapting This Pattern to Any Scenario

The program in this lesson follows a pattern you can adapt to almost any Paper 1 question:

1. Define a FUNCTION to get and validate a single piece of input
2. Use a FOR loop to collect the required number of inputs into an array
3. Process the array (total, count, find max/min, search, sort)
4. Output results using IF/ELSE or OUTPUT statements
5. Wrap in a SUBROUTINE called at the end

Not every question needs every component. But thinking in this structure before writing means you will not forget validation, will not use the wrong loop, and will not miss an ENDIF.

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

Prev

Logic Gates to Circuits: Worked Practice

Related lessons

7 Slides

Lesson

Variables, Constants and Data Types

GCSE Computer Science · AQA 8525

5 days ago

7 Slides

Lesson

Selection and Iteration

GCSE Computer Science · AQA 8525

5 days ago

7 Slides

Lesson

Arrays and Records

GCSE Computer Science · AQA 8525

5 days ago

7 Slides

Lesson

Subroutines: Procedures and Functions

GCSE Computer Science · AQA 8525

5 days ago

7 Slides

Lesson

Robust and Secure Programming

GCSE Computer Science · AQA 8525

4 days ago

7 Slides

Lesson

Computational Thinking and Representing Algorithms

GCSE Computer Science · AQA 8525

4 days ago