Pearson Edexcel · GCSE · Computer Science

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

    Input/output

    Input/Output is the vital bridge between a program and the outside world. This topic covers how to get data from users and files, validate it to prevent errors, and authenticate users securely—essential skills that underpin almost every practical programming task in your exam.

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

    Study Notes

    Overview

    Input and Output (I/O) is the foundation of interactive programming. Without it, a program cannot receive data, nor can it share its results. This topic covers how programs handle user inputs, read and write data to files (like CSVs), and ensure that the data entering the system is both valid and secure.

    In Computer Science, mastering I/O is critical because it connects theoretical algorithms to real-world applications. It directly links to other topics such as data types, algorithms, and security. In your exam, you can expect a mix of short theoretical questions (e.g., "State the difference between validation and authentication") and longer practical tasks where you must write code to read from a file, validate the data, and output a formatted result.

    Listen to the companion podcast below for an examiner's perspective on this topic:

    Key Concepts

    Concept 1: User Input and Output

    Programs need to communicate with users. In Python, the input() function is used to gather data from the keyboard, while the print() function displays data on the screen.

    Crucial Detail: The input() function always returns a string. If you ask a user for their age and they type 16, Python sees it as the text "16", not the number 16. To perform mathematical operations, you must cast (convert) the input to an integer using int() or a float using float().

    Example:
    python

    Getting string input

    name = input("Enter your name: ")

    Getting integer input (requires casting)

    age = int(input("Enter your age: "))

    Output using an f-string

    print(f"Hello {name}, next year you will be {age + 1}.")

    Concept 2: File Handling (CSV)

    Data stored in variables is lost when a program closes. To save data permanently, we write it to files. A Comma-Separated Values (CSV) file is a simple text file where each line is a record, and fields are separated by commas. It is essentially a spreadsheet saved as plain text.

    When working with files, you must specify the file mode:

    • Read (r): Opens the file to read its contents. Does not modify the file.
    • Write (w): Opens the file to write data. Warning: This overwrites any existing data in the file.
    • Append (a): Opens the file to add data to the end, preserving existing contents.

    Always use the with statement when opening files. It ensures the file is automatically closed when the block of code finishes, even if an error occurs. Examiners look for this as a sign of good programming practice.

    CSV File Handling ProcessOpen full-size image (opens in a new tab)

    Concept 3: Data Validation

    Validation is the automated checking of data entered into a system to ensure it is sensible and reasonable before it is processed. It does not check if the data is correct or true (e.g., it can check if an age is between 0 and 120, but not if you are actually 16).

    There are four main types of validation you must know:

    1. Presence Check: Ensures a field has not been left blank.
    2. Length Check: Ensures the data contains a specific number of characters (e.g., a password must be at least 8 characters).
    3. Range Check: Ensures a number falls within a specified lower and upper boundary.
    4. Pattern/Format Check: Ensures the data matches a specific format (e.g., an email address must contain an @ symbol).

    The Four Main Types of Data ValidationOpen full-size image (opens in a new tab)

    Concept 4: Authentication

    While validation checks the data, authentication checks the identity of the user. It ensures that a person is who they claim to be, usually by comparing credentials (like a username and password) against a stored lookup table or database.

    Authentication vs Validation ComparisonOpen full-size image (opens in a new tab)

    Mathematical/Scientific Relationships

    While this topic is primarily programming-focused, you must understand Boolean logic as it applies to validation. Validation rules often use comparison operators:

    • == (Equal to)
    • != (Not equal to)
    • > (Greater than)
    • < (Less than)
    • >= (Greater than or equal to)
    • <= (Less than or equal to)

    For example, a range check for a teenager's age requires compound Boolean logic: if age >= 13 and age <= 19:

    Practical Applications

    Input/Output and validation are used everywhere. When you create a new account on Instagram, length checks ensure your password is secure, and format checks ensure your email is valid. When a school takes the register, the system appends (a mode) the attendance data to a database file so it isn't lost when the computer is turned off.

    Check what you remember

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

    Reference: Pearson Edexcel

    An automated check to ensure that data entered into a system is sensible, reasonable, and meets specific criteria before processing.
    Pearson Edexcel

    Interactive Diagrams

    2 interactive diagrams to visualise key concepts

    Conceptual Flow Outline

    Start: User Login
    ➔Input Username
    Input Username
    ➔Input Password
    Input Password
    ➔Presence Check: Are fields empty?
    Presence Check: Are fields empty?
    ➔"Yes"Output: 'Fields cannot be empty'
    ➔"No"Length Check: Password >= 8 chars?
    Output: 'Fields cannot be empty'
    ➔Input Username
    Length Check: Password >= 8 chars?
    ➔"No"Output: 'Password too short'
    ➔"Yes"Lookup credentials in database
    Output: 'Password too short'
    ➔Input Password
    Lookup credentials in database
    ➔Authentication: Match found?
    Authentication: Match found?
    ➔"No"Output: 'Access Denied'
    ➔"Yes"Output: 'Access Granted'
    Output: 'Access Denied'
    ➔Input Username
    Output: 'Access Granted'
    ➔End

    Flowchart demonstrating how validation (presence, length) occurs BEFORE authentication.

    Conceptual Flow Outline

    User Types '16'
    ➔input() function
    input() function
    ➔String: '16'
    String: '16'
    ➔int() function / Casting
    int() function / Casting
    ➔Integer: 16
    Integer: 16
    ➔Mathematical Processing
    Mathematical Processing
    ➔print() function
    print() function
    ➔Output to Screen

    The data flow and casting process from user input to screen output.

    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

    A programmer is creating a registration form. State two validation checks they could use on a 'Date of Birth' field.

    2 marks
    foundation

    Hint: Think about what makes a date sensible. Can someone be born in the future? Can they leave it blank?

    Q2

    Describe how a program can authenticate a user logging into a system.

    3 marks
    standard

    Hint: What two pieces of information does the user provide, and what does the system do with them?

    Q3

    Write a Python program that asks the user to input an exam score out of 100. The program must use a loop to continuously ask for the score until a valid number between 0 and 100 inclusive is entered. Once valid, output 'Score accepted'.

    5 marks
    challenging

    Hint: You need a while loop, and you must cast the input to an integer. Think carefully about the condition for the loop to continue running.

    Q4

    Explain why a programmer should use a with statement when opening files in Python.

    2 marks
    standard

    Hint: What happens if a program crashes while a file is open normally?

    Q5

    A text file 'logs.txt' contains a list of usernames. A developer writes the following code: file = open('logs.txt', 'w'). Explain the problem with this code if the developer intended to add a new user to the list.

    2 marks
    foundation

    Hint: Look at the mode parameter 'w'. What does 'w' do to existing files?

    Ready to test yourself interactively?

    Active recall beats reading alone. Answer questions on Input/output 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 programming questions, highlight the specific requirements: inputs needed, validation rules, file modes, and exact output phrasing. Draft your logic before writing code.

    How to structure your answer

    For 'Explain' questions, use the 'Point + Example + Consequence' structure. State the fact, give an example, and explain why it matters.

    Timing

    Approximately 1 minute per mark, so a 6-mark programming question should take about 6-7 minutes.

    Common pitfalls

    • Forgetting to cast input() to an integer when asking for numbers.
    • Confusing write ('w') and append ('a') file modes.
    • Forgetting to close files (if not using a with statement).
    • Using > instead of >= in length or range checks, accidentally excluding the boundary value.

    What the command words want

    Compare
    Identify similarities AND differences - use comparative language (e.g., 'whereas', 'however').
    Explain
    Say HOW or WHY - use 'because' to link cause and effect. Provide examples.
    Describe
    Say what happens or what something is like - use correct terminology. E.g., 'A length check ensures the input contains a specific number of characters.'
    Calculate
    Show working, use correct formula, include units.
    State/Give
    Brief factual answer - 1-2 words or a short phrase. No explanation needed.
    Write a program
    Write syntactically correct code (usually Python) or clear pseudocode. Ensure all variables are initialized and logic flows correctly.
    Watch or listen (optional)
    🎙 Podcast Episode
    Input/output
    0:00-0:00

    Test your understanding of Input/output

    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.