You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers input and output operations as required by OCR J277 Section 2.3. Input and output (often abbreviated as I/O) are fundamental to every program — without them, a program cannot receive data from the user or display results.
Input is data entered into a program by the user or received from another source (such as a file or sensor). In OCR GCSE Computer Science, input typically means data entered via the keyboard.
OCR Pseudocode:
name = input("What is your name? ")
age = int(input("How old are you? "))
Python:
name = input("What is your name? ")
age = int(input("How old are you? "))
| Point | Explanation |
|---|---|
input() always returns a string | Even if the user types 42, it is stored as the string "42" |
| You must cast for numbers | Use int() for integers, float() (or real() in OCR pseudocode) for decimals |
| The prompt message is optional | But it is good practice to tell the user what to enter |
| Input waits for the user | The program pauses until the user presses Enter |
OCR Exam Tip: If the exam question says "the user enters a number", you must use
int(input())orreal(input()). Forgetting to cast is a common mistake that means arithmetic operations would fail or give unexpected results.
Output is data displayed by the program, typically on the screen. In OCR pseudocode and Python, the print() function is used for output.
OCR Pseudocode:
print("Hello, world!")
name = "Alice"
print("Welcome, " + name)
score = 95
print("Your score is: " + str(score))
Python:
print("Hello, world!")
name = "Alice"
print("Welcome, " + name)
score = 95
print("Your score is:", score) # Python's print() can accept multiple arguments
print("Your score is: " + str(score)) # String concatenation version
When combining text and numbers in output, you often need to convert numbers to strings:
OCR Pseudocode:
price = 9.99
quantity = 3
total = price * quantity
print("Total: £" + str(total))
Python:
price = 9.99
quantity = 3
total = price * quantity
print("Total: £" + str(total))
# Or using f-strings (more modern Python):
print(f"Total: £{total}")
# Or using format to 2 decimal places:
print(f"Total: £{total:.2f}")
A typical program follows an Input → Process → Output pattern:
OCR Pseudocode:
// Input
length = real(input("Enter length: "))
width = real(input("Enter width: "))
// Process
area = length * width
// Output
print("The area is: " + str(area))
Python:
# Input
length = float(input("Enter length: "))
width = float(input("Enter width: "))
# Process
area = length * width
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.