GCSE AQA 8525 OCR J277 Cambridge 0478

Python Programming for GCSE Computer Science

Python is the most widely used programming language in UK GCSE Computer Science classrooms. This guide covers every Python skill assessed on AQA, OCR and Cambridge papers — with worked examples, exam technique tips and common mistakes to avoid.

Python skills you need for the GCSE exam

Organised from foundation to higher-level topics. All of these can appear in Paper 2 / Component 2 on the written exam — you need to write and trace Python code from memory.

Variables, Data Types & Input/Output

Foundation

Key points

  • Integer, float, string, boolean — know when to use each
  • int(), float(), str() type conversion
  • input() always returns a string — convert before arithmetic
  • print() with comma-separated values and f-strings
  • Constants vs variables — use UPPER_CASE for constants
⚠️ Exam watch: A common mistake: forgetting to convert input() to int before adding to a number. "5" + 3 gives a TypeError; int("5") + 3 gives 8.

Worked example

name = input("Enter your name: ")
age = int(input("Enter your age: "))
print(f"Hello {name}, you are {age} years old.")

# Type conversion
price = float("9.99")   # string → float
code  = str(42)         # int → string

Selection — IF, ELIF, ELSE

Foundation

Key points

  • IF condition: / ELIF condition: / ELSE:
  • Comparison operators: == != > < >= <=
  • Logical operators: and or not
  • Nested IF statements
  • Common exam task: grade boundaries, input validation
⚠️ Exam watch: elif conditions are checked in order — the first True branch runs and the rest are skipped. Make sure your boundary conditions use >= not >.

Worked example

score = int(input("Enter score: "))

if score >= 90:
    grade = "A"
elif score >= 70:
    grade = "B"
elif score >= 50:
    grade = "C"
else:
    grade = "Fail"

print(f"Grade: {grade}")

Iteration — FOR and WHILE loops

Foundation

Key points

  • for i in range(n): — repeats n times (0 to n-1)
  • for i in range(start, stop): — start to stop-1
  • for item in list: — iterate over a list
  • while condition: — repeat until condition is False
  • break and continue — exit loop or skip to next iteration
⚠️ Exam watch: range(5) gives 0,1,2,3,4 — NOT 1,2,3,4,5. range(1,6) gives 1,2,3,4,5. This catches many students in trace table questions.

Worked example

# FOR loop — count 1 to 5
for i in range(1, 6):
    print(i)

# WHILE loop — keep asking until valid input
number = -1
while number < 0:
    number = int(input("Enter a positive number: "))
print(f"You entered: {number}")

# Accumulator pattern
total = 0
for i in range(1, 11):
    total += i
print(f"Sum 1-10: {total}")   # 55

Functions and Return Values

Core

Key points

  • def function_name(parameters):
  • return value — sends a value back to the caller
  • Difference between a function (returns value) and procedure (no return)
  • Local vs global variables
  • Calling a function: result = function_name(argument)
⚠️ Exam watch: A function MUST have a return statement to give back a value. A procedure performs an action but returns nothing (or None in Python). Exam questions often ask you to identify which one is being used.

Worked example

def calculate_area(length, width):
    area = length * width
    return area

# Call the function
room_area = calculate_area(5, 3)
print(f"Area: {room_area} m²")   # Area: 15 m²

# Function with validation
def is_valid_grade(grade):
    return 0 <= grade <= 100

print(is_valid_grade(85))   # True
print(is_valid_grade(110))  # False

Lists and List Operations

Core

Key points

  • Creating a list: numbers = [4, 2, 7, 1]
  • Indexing: numbers[0] is the first item
  • Slicing: numbers[1:3] gives items at index 1 and 2
  • .append(item) — add to end
  • len(numbers) — number of items
  • Iterating: for item in numbers:
  • Searching: if value in numbers:
⚠️ Exam watch: Indexing starts at 0. The last item is at index len(list)-1 or index -1. A common trace error is forgetting that range(len(scores)) gives 0 to len-1.

Worked example

scores = [75, 88, 62, 91, 50]

# Access and modify
print(scores[0])        # 75 — first item
print(scores[-1])       # 50 — last item
scores.append(83)       # Add 83 to end

# Find maximum without max()
highest = scores[0]
for score in scores:
    if score > highest:
        highest = score
print(f"Top score: {highest}")  # 91

# Count items over 70
count = 0
for score in scores:
    if score >= 70:
        count += 1
print(f"{count} students passed")

String Manipulation

Core

Key points

  • len(string) — number of characters
  • string[i] — character at index i
  • string[start:end] — slice
  • string.upper() / string.lower()
  • string.split(delimiter) — split into list
  • string + string — concatenation
  • str in string — check if substring present
⚠️ Exam watch: String indexing uses the same rules as list indexing. Slicing string[0:4] gives characters at indices 0,1,2,3 — NOT including index 4.

Worked example

word = "Computer"

print(len(word))          # 8
print(word[0])            # C
print(word[-1])           # r
print(word[0:4])          # Comp
print(word.upper())       # COMPUTER
print(word.lower())       # computer

# Reverse a string
reversed_word = word[::-1]
print(reversed_word)      # retupmoC

# Check if palindrome
def is_palindrome(s):
    s = s.lower()
    return s == s[::-1]

print(is_palindrome("racecar"))  # True

File Handling

Higher

Key points

  • open("filename.txt", "r") — read mode
  • open("filename.txt", "w") — write (overwrites)
  • open("filename.txt", "a") — append (adds to end)
  • with open(...) as f: — automatic close
  • f.read() — read entire file
  • f.readlines() — read into list of lines
  • f.write("text") — write to file
  • .strip() — remove \n and whitespace from line
⚠️ Exam watch: Always use the with statement — it closes the file automatically even if an error occurs. Remember .strip() removes the \n newline character at the end of each line when reading.

Worked example

# Writing to a file
with open("scores.txt", "w") as f:
    f.write("Alice,88\n")
    f.write("Bob,74\n")

# Reading from a file
with open("scores.txt", "r") as f:
    for line in f:
        line = line.strip()          # Remove newline
        name, score = line.split(",")
        print(f"{name}: {score}")

Searching and Sorting Algorithms in Python

Higher

Key points

  • Linear search — check each item in order
  • Binary search — halve the search space (sorted list only)
  • Bubble sort — compare adjacent pairs, swap if wrong order
  • Insertion sort — build sorted section from left
⚠️ Exam watch: In the bubble sort exam question, show EVERY comparison in EVERY pass, including ones where no swap is made. Each comparison earns a mark. Note the early termination when no swaps occur in a pass.

Worked example

# Linear search
def linear_search(lst, target):
    for i in range(len(lst)):
        if lst[i] == target:
            return i        # Found at index i
    return -1               # Not found

# Bubble sort
def bubble_sort(lst):
    n = len(lst)
    for pass_num in range(n - 1):
        swapped = False
        for j in range(n - 1 - pass_num):
            if lst[j] > lst[j + 1]:
                lst[j], lst[j + 1] = lst[j + 1], lst[j]
                swapped = True
        if not swapped:     # Early termination
            break
    return lst

print(bubble_sort([5, 2, 8, 1, 9]))  # [1, 2, 5, 8, 9]

Practice tools

🐍

Struggling with Python for GCSE?

One-to-one Python tutoring sessions with an experienced Computer Science teacher. Work through the programming questions you find hardest — from basic loops to writing full algorithms — in a supportive online environment.

Frequently asked questions — GCSE Python

Is Python required for GCSE Computer Science?

Python is not mandated by any exam board — AQA 8525, OCR J277 and Cambridge 0478 all accept any high-level language. However, Python is by far the most widely used language in UK schools for GCSE CS, and the question papers use a pseudocode that maps very closely to Python syntax. Most mark schemes accept Python code directly.

What Python topics come up in the GCSE exam?

The most commonly assessed Python topics at GCSE are: variables and data types, input() and print(), IF/ELIF/ELSE selection, FOR and WHILE loops, functions and return values, lists and list operations, string manipulation (len, slicing, concatenation), file reading/writing, and simple algorithms such as searching and sorting.

Do I need to memorise Python syntax for the exam?

Yes. The written paper is closed-book and you cannot run code. You must write correct or near-correct Python from memory. The most commonly needed syntax is: if/elif/else, for i in range(), while, def/return, print(), input(), int(), str(), len(), and list operations like .append() and indexing.

How is Python assessed in the GCSE Computer Science exam?

Python (or pseudocode) questions appear on Paper 2 / Component 2 for AQA, OCR and Cambridge. Typical question types: write a program to do X, trace through the given code and write what it outputs, identify and fix the bug in the program, extend or modify existing code.

What is the difference between pseudocode and Python at GCSE?

Pseudocode is a human-readable representation of an algorithm using structured English and programming constructs, without the strict syntax rules of a real language. Each exam board has its own pseudocode style. Python is a real programming language you can run. In the exam, both are accepted — but stick to the style the question uses if it provides code, and use Python if you are more comfortable with it.

Related resources