Pearson Edexcel · GCSE · Computer Science

    Course version: Pearson-GCSE-Computer-Science · Version from Mar 2026

    Programming

    Master the core of GCSE Computer Science with this comprehensive guide to programming in Python 3. From basic sequence to complex file handling, learn the exact skills and examiner-approved techniques needed to write robust code and secure top marks in your onscreen assessment.

    • 5 min read
    • 3 worked examples
    • 5 practice questions
    • 6 key terms

    Study Notes

    Overview

    GCSE Computer Science: ProgrammingOpen full-size image (opens in a new tab)

    Programming is the beating heart of GCSE Computer Science. It transforms theoretical computational thinking into practical, working solutions. In this topic, you will move beyond understanding how computers work and learn how to make them work for you using Python 3.

    This unit is crucial because it bridges the gap between problem-solving (decomposition and abstraction) and implementation. You will be assessed on your ability to design, write, test, and refine code in a live, two-hour onscreen assessment. Examiners are looking for more than just code that runs; they want to see robust, readable, and efficient solutions.

    Typical exam questions range from tracing the output of short algorithms and identifying errors, to writing complete subprograms or file-handling routines from scratch. Mastering this topic also provides synoptic links to algorithms, data representation, and system security.

    Key Concepts

    Concept 1: The Three Programming Constructs

    Every program ever written, from a simple calculator to a complex 3D game, is built using just three fundamental building blocks: Sequence, Selection, and Iteration.

    The Three Programming ConstructsOpen full-size image (opens in a new tab)

    • Sequence is the simplest construct. Instructions are executed one after the other, in order, from top to bottom. If you get the sequence wrong, the program will execute the wrong logic.
    • Selection allows your program to make decisions based on conditions (evaluating to True or False). In Python, this is implemented using if, elif, and else statements. It allows the program to branch into different paths.
    • Iteration is the process of repeating instructions. Python uses for loops (count-controlled, when you know how many times to repeat) and while loops (condition-controlled, repeating until a condition changes).

    Example: A program asking for a password uses sequence to ask the question, selection to check if the password is correct, and iteration (a while loop) to keep asking until the correct password is provided.

    Concept 2: Subprograms (Functions vs Procedures)

    As programs grow larger, writing all the code in one long block becomes unmanageable. We use decomposition to break the problem down into smaller, manageable chunks called subprograms.

    Functions vs ProceduresOpen full-size image (opens in a new tab)

    In Python, there are two types of subprograms:

    • Functions: Perform a specific task AND return a value to the main program using the return keyword.
    • Procedures: Perform a specific task but DO NOT return a value. They simply execute an action, like printing a menu to the screen.

    Examiners frequently test your understanding of this distinction. If a question asks you to write a function, omitting the return statement will cost you marks.

    Concept 3: Data Types and Structures

    Variables are named memory locations used to store data while a program is running. You must use the correct data type for the data you are storing:

    • Integer (int): Whole numbers (e.g., 42, -5).
    • Real/Float (float): Numbers with a decimal point (e.g., 3.14).
    • String (str): Text, enclosed in quotation marks (e.g., "Hello").
    • Boolean (bool): Can only hold one of two values: True or False.

    When you need to store multiple related items under a single identifier, you use a data structure. Python uses Lists (often referred to as arrays in other languages). Lists are zero-indexed, meaning the first item is at position 0.

    Concept 4: Error Types and Debugging

    No programmer writes perfect code first time. You must be able to identify and fix three types of errors:

    Types of Programming ErrorsOpen full-size image (opens in a new tab)

    • Syntax Errors: Breaking the grammatical rules of the programming language (e.g., missing a colon : or a bracket). The code will not run at all.
    • Logic Errors: The code runs without crashing, but produces the wrong output because the underlying algorithm is flawed (e.g., adding instead of subtracting).
    • Runtime Errors: The code is syntactically correct but crashes while running due to an impossible operation (e.g., trying to divide by zero or opening a file that doesn't exist).

    Practical Applications

    File Handling

    Programs need to save data permanently; otherwise, everything is lost when the program closes. You must know how to read from and write to CSV (Comma Separated Values) text files.

    Key Python commands:

    • file = open("data.csv", "r") - Opens for reading.
    • file = open("data.csv", "w") - Opens for writing (overwrites existing data).
    • file = open("data.csv", "a") - Opens for appending (adds to the end).
    • file.close() - Always close files to free up system resources.

    Input Validation

    Robust programs don't crash when users enter silly data. Input validation uses iteration (while loops) to repeatedly ask for input until the user provides valid data (e.g., a number between 1 and 10). This is a critical skill for the exam.


    Listen to the Podcast Revision Episode

    Reinforce your learning by listening to our 3-minute revision podcast covering all these concepts, common mistakes, and a quick-fire quiz!

    Check what you remember

    Read the wording for your board, then hide it and explain Variable in your own words. Rough notes are fine. This is a self-check, with no mark or grade.

    Reference: Pearson Edexcel

    A named memory location used to store data that can change while the program is running.
    Pearson Edexcel

    Interactive Diagrams

    2 interactive diagrams to visualise key concepts

    Conceptual Flow Outline

    Start Input Validation
    ➔Ask user for score
    Ask user for score
    ➔Is score between 0 and 100?
    Is score between 0 and 100?
    ➔"No"Print 'Invalid, try again'
    ➔"Yes"Accept score and continue
    Print 'Invalid, try again'
    ➔Ask user for score

    Flowchart demonstrating a typical input validation loop (Iteration and Selection).

    Conceptual Flow Outline

    Main Program
    ➔"Calls function with argument (e.g., 50)"Function: calculate_tax(amount)
    Function: calculate_tax(amount)
    ➔"Calculates 50 * 0.20 = 10"Function: calculate_tax(amount)
    ➔"Returns 10"Value returned to Main Program

    How data flows into and out of a Function.

    Worked Examples

    3 worked examples — open one to explore the question and available guidance.

    Practice Questions

    Try the question, then reveal an answer plan or example response

    Q1

    State the data type that would be most appropriate to store a person's telephone number, and justify your choice. (2 marks)

    2 marks
    foundation

    Hint: Think about whether you ever need to do maths with a phone number, and what character phone numbers often start with.

    Q2

    Write a Python program that asks the user to input the temperature in Celsius. If the temperature is below 0, output 'Freezing'. If it is between 0 and 100 inclusive, output 'Liquid'. If it is above 100, output 'Boiling'. (4 marks)

    4 marks
    standard

    Hint: You will need to use an if/elif/else structure and remember to cast your input.

    Q3

    A text file called scores.txt contains a list of high scores, one on each line. Write a Python program that reads the file, calculates the total of all the scores, and prints the total. (5 marks)

    5 marks
    challenging

    Hint: You need to open the file, loop through it, cast each line to an integer, add it to a running total, and then close the file.

    Q4

    Explain the difference between a local variable and a global variable. (2 marks)

    2 marks
    standard

    Hint: Think about where the variable is created and where it can be seen by the program.

    Q5

    Look at the following code:
    python
    for i in range(1, 4):
    print(i * 2)

    State the exact output of this code. (3 marks)

    3 marks
    foundation

    Hint: Remember how the range() function works in Python. Does it include the stop number?

    Ready to test yourself interactively?

    Active recall beats reading alone. Answer questions on Programming with instant AI scoring and mark scheme guidance.

    Start interactive practice

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge

    Exam technique

    How to turn what you know into marks

    How to approach the question

    For coding questions: 1. Read the requirements twice. 2. Identify inputs, processes, and outputs. 3. Write pseudocode or a quick plan on scrap paper. 4. Code the solution. 5. Test it with boundary data.

    How to structure your answer

    For trace tables: Work methodically line by line. Update variable values only when they actually change in the code. Cross out old values to avoid confusion.

    Timing

    Approximately 1 minute per mark. In the 2-hour onscreen assessment, allocate time for planning and debugging, not just typing.

    Common pitfalls

    • Forgetting to cast input() strings to integers or floats using int() or float().
    • Confusing = (assignment) with == (comparison for equality).
    • Incorrect indentation causing syntax errors or logic errors inside loops/if statements.
    • Writing a procedure (using print) when the question explicitly asked for a function (requiring return).

    What the command words want

    Trace
    Complete a trace table showing the changing values of variables as an algorithm executes.
    Refine
    Fix errors in provided code or make it more efficient/robust.
    Explain
    Say WHY a piece of code is written a certain way, or WHY an error occurs.
    Describe
    Explain what a piece of code does line by line.
    State/Give
    Brief factual answer - e.g., naming a data type.
    Write/Develop
    Produce syntactically correct Python code that solves the given problem.
    Watch or listen (optional)
    Interactive Video Explainer
    AI Generated • 3-4 Mins
    🎙 Podcast Episode
    Programming
    0:00-0:00

    Test your understanding of Programming

    Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

    Take topic quiz

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge

    More Computer Science Study Guides

    View all

    Algorithms

    Pearson Edexcel
    GCSE

    Master the logic behind every computer program. This topic covers how to design, trace, and evaluate algorithms using sequence, selection, and iteration, plus the essential searching and sorting techniques you'll need for your exam.

    Binary

    Pearson Edexcel
    GCSE

    Mastering binary is essential for understanding how computers store and process all data. This topic covers converting between number bases, performing binary arithmetic, understanding shifts, and recognizing overflow — key skills that frequently appear in exams and form the foundation of computer science.

    Constructs

    Pearson Edexcel
    GCSE

    Master the fundamental building blocks of all software: Sequence, Selection, and Iteration. This topic is the core of Computer Science and tests your ability to think like a real programmer, enabling you to read, trace, and write code confidently for the exam.

    Cybersecurity

    Pearson Edexcel
    GCSE

    Master the critical threats to digital systems and the methods used to protect them. This high-yield GCSE Computer Science topic explores malware, social engineering, and the technical defences essential for earning top marks.

    Data

    Pearson Edexcel
    GCSE

    Master the language of computers. This topic covers how binary underpins everything from text and images to sound and data compression, ensuring you can secure crucial calculation marks in your exam.

    Data storage and compression

    Pearson Edexcel
    GCSE

    Master the fundamentals of binary data storage and the critical importance of compression. This topic is calculation-heavy and frequently tested, requiring you to confidently convert between binary units and understand the trade-offs between lossless and lossy compression methods.