Input/output — Edexcel GCSE Computer Science
Verified courseTeaching note checked against the official specification.
Input/output explained
Input/output covers 4 specification points, including Be able to write programs that accept and… and Be able to write programs that read from and….
Read the full explanation
Open a point below for its explanation and revision guidance.
6.4.1 be able to write programs that accept and respond appropriately to user input
This criterion requires you to write working program code that reads data entered by a user and then reacts to it correctly. Accepting input means using the input function to read a value, storing it in a named variable and converting it to the right data type, for example wrapping input in int() when a whole number is needed. Responding appropriately means the program uses that value in a sensible way: validating it, branching on it with selection, repeating with iteration, or producing output that depends on what was entered. For example, a program might ask for a test score, convert it to an integer, check it is between 0 and 100, then print a grade based on the value. Your answer should show the input statement, the variable, any type conversion, the logic that uses the value and the output, so a reader can trace how the response depends on the user's entry.
6.4.2 be able to write programs that read from and write to comma separated value text files
This criterion requires you to write working programs that both read data from and write data to comma separated value (CSV) text files. A CSV file stores tabular data as plain text, with one record per line and fields separated by commas, for example a line such as Ada,Lovelace,1815. To read, open the file in read mode, loop through each line, strip the trailing newline, split the line on commas into a list of fields, and use those fields in your program. To write, open the file in write or append mode and build each output line by joining fields with commas, adding a newline, then writing it. You must handle the file correctly: close it after use, and consider what happens when a field itself contains a comma. Your program should demonstrate both directions of data flow, not just one.
6.4.3 understand the need for and be able to write programs that implement validation (length check, presence check, range check, pattern check)
Validation checks that data entered into a program is sensible and complete before it is processed. It cannot prove data is true, only that it meets rules. A length check confirms a string has an allowed number of characters, such as a username between 4 and 12 characters. A presence check confirms a field is not empty, for example rejecting a blank email box. A range check confirms a number or ordered value lies between limits, such as a test score from 0 to 100. A pattern check confirms text matches a required format, such as a postcode or a date in DD/MM/YYYY form. Programs implement these with selection and iteration: read input, test the condition, and if it fails, display a message and ask again until valid. This protects later stages from missing, out-of-range or wrongly formatted data.
6.4.4 understand the need for and be able to write programs that implement authentication (ID and password, lookup)
Authentication confirms that a user is who they claim to be before allowing access. A common method asks for an ID and a password, then performs a lookup: the program searches stored records for the supplied ID and compares the stored password with the one entered. If both match, access is granted; otherwise access is denied and the user may be asked to try again. The need is to protect systems and data from unauthorised use. Programs implement this with selection, iteration and data structures such as lists or dictionaries. A lookup may also retrieve other details linked to the ID. Authentication differs from validation: validation checks the format of input, while authentication checks identity against stored credentials.
Your focus
- Write code that reads user input into a variable and converts it to the required data type.
- Use selection or iteration so the program's output depends on the value entered.
- Validate input and produce clear output that responds appropriately to the user.
Show all 12 objectives
- Open a CSV text file, read each line, strip the newline and split the line on commas to obtain fields.
- Construct a CSV record by joining fields with commas and a newline, then write it to a file in the appropriate mode.
- Verify that written CSV data can be read back and parsed into the same fields and records.
- Explain why programs validate input and what validation can and cannot guarantee.
- Identify and describe length, presence, range and pattern checks in a given scenario.
- Write program code that applies a named validation check and repeats input until the data is valid.
- Explain why authentication is needed and how ID and password authentication works.
- Describe a lookup that finds a stored record and compares credentials.
- Write program code that performs a lookup and grants or denies access based on matching ID and password.
Input/output exam tips
Marking Points
- Uses an input function to read a value from the user and stores it in a named variable.
- Converts the input to the correct data type, for example int() for a whole number or float() for a decimal, before using it in calculations or comparisons.
- Responds to the input with appropriate logic such as selection (if/elif/else) or iteration, so the output depends on the value entered.
- Validates the input where appropriate, for example checking a number is within an expected range or that text is not empty.
- Produces clear output that reflects the user's input, such as a message, grade or calculated result.
- Opens the CSV file in the correct mode for the task: read mode for reading, write or append mode for writing, and closes it after use.
- Reads the file line by line, removes the trailing newline from each line, and splits each line on the comma character to obtain individual fields.
- Uses the resulting fields correctly in the program, for example converting a numeric field to an integer or real before calculation.
- Builds each output record by joining the fields with commas and appending a newline before writing it to the file.
- Writes data that can be read back correctly, so the output file remains valid CSV with consistent field order and count.
- Demonstrates both reading from and writing to CSV files within the same program or across clearly linked tasks.
- Handles edge cases such as an empty file, a missing file, or a field containing a comma, and explains the chosen approach.
- Validation checks that input is sensible, complete and within allowed rules; it does not prove the data is accurate or true.
- A length check tests the number of characters in a string against a minimum, maximum or exact length.
- A presence check tests that a required field has not been left empty.
- A range check tests that a value lies between a lower and an upper limit, inclusive or exclusive as specified.
- A pattern check tests that text matches a required format, such as a postcode or date layout.
- Programs implement validation using selection and iteration so invalid input is rejected and the user is prompted to re-enter.
- Authentication confirms a user's identity before granting access to a system or its data.
- A typical method collects an ID and a password from the user.
- A lookup searches stored records for the supplied ID and retrieves the associated stored password or credential.
- The program compares the entered password with the stored password and grants access only when both the ID and password match.
- If the ID is not found or the password does not match, the program denies access and may allow a limited number of retries.
- Authentication is implemented using selection, iteration and data structures such as lists or dictionaries.
Examiner Tips
- 💡Write the input line first, then immediately convert and store the value so the type is clear.
- 💡Trace your code with a sample input, such as 75 or 'yes', to check the response is correct.
- 💡Include validation and a clear output message so the program responds appropriately rather than just reading a value.
- 💡Plan your program before writing: identify which file you read, which file you write, and the exact field order in each record.
- 💡Test with a small sample CSV file and read your own output back to confirm the fields split correctly and the record count matches.
- 💡Comment your code to show where reading happens and where writing happens, so an assessor can see both skills clearly.
- 💡Read the scenario and name the check that matches the rule, then state the condition the program must test.
- 💡When asked to write code, include a loop that repeats until the input passes the check, and show the error message path.
- 💡Use precise terms: length, presence, range and pattern, and avoid saying validation proves data is correct.
- 💡State the purpose of authentication before describing the ID and password process.
- 💡When writing code, show the lookup step and the comparison, and make the access decision depend on both matching.
- 💡Use terms such as stored record, lookup, credentials and access granted or denied accurately.
Common Mistakes
- Forgetting that input returns a string: comparing or adding the raw input without converting it with int() or float() causes errors or unexpected results.
- Using a variable before it is assigned or misspelling the variable name, so the program cannot use the value the user entered.
- Writing logic that ignores the input, for example always printing the same message regardless of what the user typed, which does not respond appropriately.
- Forgetting to strip the newline character before splitting a line, so the final field contains an unwanted newline; the correction is to remove trailing whitespace or newline characters first.
- Splitting on the wrong delimiter, such as a space or semicolon, when the file uses commas; the correction is to split on the comma character that defines the CSV format.
- Writing fields without inserting commas or newlines, producing a file that cannot be parsed back into records; the correction is to join fields with commas and add a newline per record.
- Leaving the file open or not handling the case where the file does not exist; the correction is to close files after use and check or handle missing files.
- Confusing validation with verification: validation checks that data is sensible against rules, while verification checks that data has been copied or entered accurately. Correct by stating that validation cannot confirm a value is true.
- Treating a presence check as a length check: a presence check only tests that something has been entered, whereas a length check tests how many characters were entered. Correct by matching each check to the rule it enforces.
- Assuming a range check applies only to numbers: it can also apply to ordered values such as letters or dates. Correct by describing it as testing whether a value lies between limits.
- Writing a pattern check as a simple equality test: a pattern check matches a format, not one exact string. Correct by describing it as testing the structure of the input.
- Confusing authentication with validation: validation checks that input is in a sensible format, while authentication checks identity against stored credentials. Correct by stating that authentication compares entered details with stored records.
- Thinking a lookup means checking the password only: a lookup must find the record for the supplied ID first, then compare the password. Correct by describing both stages.
- Assuming authentication guarantees the data is accurate: it only confirms the credentials match stored records. Correct by stating that authentication controls access, not data truth.
- Writing code that grants access when either the ID or the password matches: both must match the same stored record. Correct by testing the combined condition.