Input – any data a program receives from the outside world.
Output – any data a program sends out to the user or another system.
| Device / Channel | Direction | Typical Use in Programs |
|---|---|---|
| Keyboard | Input | Enter numbers, text, menu choices |
| Mouse / Touchscreen | Input | Select items, click buttons, draw |
| Screen (monitor) | Output | Display results, prompts, graphics |
| Printer | Output | Hard‑copy reports, receipts |
| File (disk, SSD) | Both | Read data, write results, store records |
| Network (NIC, Internet) | Both | Download data, send API requests, chat |
| Sensor (temperature, light, etc.) | Input | Collect real‑world measurements |
| Actuator (motor, speaker) | Output | Control hardware, produce sound |
input(), print() (Python) or Scanner, System.out (Java) are wrappers around OS services.The Cambridge syllabus expects you to recognise the following categories:
OPEN url "http://example.com/data" FOR INPUT READ line FROM url CLOSE url WRITE "Data received: ", line
READ variable // read a value from the user WRITE expression // display a value or message
OPEN fileName FOR INPUT // open an existing file for reading OPEN fileName FOR OUTPUT // create (or overwrite) a file for writing READ fileVariable FROM file // read a record from the file WRITE expression TO file // write a record to the file CLOSE file // release the file
OPEN url "https://api.example.com/quote" FOR INPUT READ line FROM url CLOSE url WRITE "Quote received: ", line
# read a line of text
name = input("Enter your name: ")
# read an integer, with basic validation
while True:
try:
age = int(input("Enter your age: "))
break
except ValueError:
print("Please enter a valid integer.")
print("Hello", name, "- you are", age, "years old.")
# Write to a file (creates/overwrites)
with open("scores.txt", "w") as f:
f.write("Alice 85")
f.write("Bob 78")
# Read from a file
with open("scores.txt", "r") as f:
for line in f:
print("Record:", line.strip())
import urllib.request
url = "https://api.example.com/quote"
with urllib.request.urlopen(url) as response:
data = response.read().decode('utf-8')
print("Quote received:", data)
# read 5 test scores into a list and compute the average
scores = []
for i in range(5):
s = int(input(f"Enter score {i+1}: "))
scores.append(s)
total = sum(scores)
average = total / len(scores)
print("Average score =", average)
def get_positive_int(prompt):
while True:
try:
value = int(input(prompt))
if value > 0:
return value
print("Value must be positive.")
except ValueError:
print("Please enter a valid integer.")
import java.util.Scanner;
Scanner sc = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = sc.nextLine();
System.out.print("Enter your age: ");
int age = sc.nextInt();
System.out.println("Hello " + name + " - you are " + age + " years old.");
sc.close();
import java.io.*;
try (PrintWriter out = new PrintWriter(new FileWriter("scores.txt"));
BufferedReader in = new BufferedReader(new FileReader("scores.txt"))) {
// write records
out.println("Alice 85");
out.println("Bob 78");
// read records
String line;
while ((line = in.readLine()) != null) {
System.out.println("Record: " + line);
}
} catch (IOException e) {
System.err.println("File error: " + e.getMessage());
}
import java.net.*;
import java.io.*;
URL url = new URL("https://api.example.com/quote");
try (BufferedReader br = new BufferedReader(
new InputStreamReader(url.openStream()))) {
String line = br.readLine();
System.out.println("Quote received: " + line);
}
// read 5 scores into an array and compute the average
int[] scores = new int[5];
int total = 0;
for (int i = 0; i < scores.length; i++) {
System.out.print("Enter score " + (i+1) + ": ");
scores[i] = sc.nextInt();
total += scores[i];
}
double average = total / (double) scores.length;
System.out.println("Average = " + average);
int choice;
do {
System.out.println("Menu");
System.out.println("1 – Add two numbers");
System.out.println("2 – Find largest of three");
System.out.println("0 – Quit");
System.out.print("Enter choice: ");
choice = sc.nextInt();
switch (choice) {
case 1:
System.out.print("a: "); int a = sc.nextInt();
System.out.print("b: "); int b = sc.nextInt();
System.out.println("Sum = " + (a + b));
break;
case 2:
System.out.print("x: "); int x = sc.nextInt();
System.out.print("y: "); int y = sc.nextInt();
System.out.print("z: "); int z = sc.nextInt();
int max = Math.max(x, Math.max(y, z));
System.out.println("Largest = " + max);
break;
case 0:
System.out.println("Good‑bye!");
break;
default:
System.out.println("Invalid choice – try again.");
}
} while (choice != 0);
IOException (Java) or try/except (Python).flush() (Java) or use the with statement (Python) which flushes automatically.Example pseudocode that reads five scores, stores them in an array, and calculates the average:
DECLARE scores[5] : INTEGER
total ← 0
FOR i ← 1 TO 5 DO
READ scores[i] // input
total ← total + scores[i] // accumulate
END FOR
average ← total / 5
WRITE "Average = ", average
Trace table (sample input: 12, 15, 9, 20, 14)
| Step | i | scores[i] | total | Output |
|---|---|---|---|---|
| 1 (read 1) | 1 | 12 | 12 | |
| 2 (read 2) | 2 | 15 | 27 | |
| 3 (read 3) | 3 | 9 | 36 | |
| 4 (read 4) | 4 | 20 | 56 | |
| 5 (read 5) | 5 | 14 | 70 | |
| 6 (calculate) | – | – | 70 | |
| 7 (output) | – | – | 70 | Average = 14 |
Input and output connect a program with the real world. For the IGCSE you must be able to:
DECLARE scores[5] : INTEGER
total ← 0
FOR i ← 1 TO 5 DO
_______ // read each score
total ← total + ______
END FOR
average ← total / 5
WRITE "Average score = ", average
switch and a do‑while loop) that offers the user:
data.txt, counts how many lines contain the word “error”, and writes the count to a new file called report.txt.Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.