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.
Open 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:
- Presence Check: Ensures a field has not been left blank.
- Length Check: Ensures the data contains a specific number of characters (e.g., a password must be at least 8 characters).
- Range Check: Ensures a number falls within a specified lower and upper boundary.
- Pattern/Format Check: Ensures the data matches a specific format (e.g., an email address must contain an
@symbol).
Open 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.
Open 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.
Interactive Diagrams
2 interactive diagrams to visualise key concepts
Conceptual Flow Outline
Flowchart demonstrating how validation (presence, length) occurs BEFORE authentication.
Conceptual Flow Outline
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
A programmer is creating a registration form. State two validation checks they could use on a 'Date of Birth' field.
Hint: Think about what makes a date sensible. Can someone be born in the future? Can they leave it blank?
Describe how a program can authenticate a user logging into a system.
Hint: What two pieces of information does the user provide, and what does the system do with them?
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'.
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.
Explain why a programmer should use a with statement when opening files in Python.
Hint: What happens if a program crashes while a file is open normally?
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.
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.
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
withstatement). - 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)
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.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge