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
# Output
print("The area is:", area)
OCR Exam Tip: Many exam questions follow the Input-Process-Output pattern. When writing algorithms, clearly separate these three stages. This makes your code easier to read and demonstrates structured thinking.
The Input-Process-Output cycle, including the cast step that exam candidates frequently forget, is shown below:
flowchart TD
A([Start]) --> B[Prompt user with input message]
B --> C[Read raw value as string from input]
C --> D{"Will value be<br/>used in arithmetic?"}
D -->|Yes| E[Cast: int or real / float]
D -->|No| F[Keep as string]
E --> G[Process: calculate result]
F --> G
G --> H[Convert numbers to string with str]
H --> I[print formatted output]
I --> J([End])
Question: Write a program that asks the user for a temperature in Celsius and converts it to Fahrenheit. The formula is: F = (C × 9/5) + 32.
OCR Pseudocode:
celsius = real(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9 / 5) + 32
print(str(celsius) + "°C is " + str(fahrenheit) + "°F")
Python:
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9 / 5) + 32
print(f"{celsius}°C is {fahrenheit}°F")
OCR Pseudocode:
num1 = real(input("Enter first number: "))
num2 = real(input("Enter second number: "))
operator = input("Enter operator (+, -, *, /): ")
if operator == "+" then
result = num1 + num2
elseif operator == "-" then
result = num1 - num2
elseif operator == "*" then
result = num1 * num2
elseif operator == "/" then
if num2 != 0 then
result = num1 / num2
else
print("Error: cannot divide by zero")
endif
else
print("Invalid operator")
endif
print("Result: " + str(result))
Python:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operator = input("Enter operator (+, -, *, /): ")
if operator == "+":
result = num1 + num2
elif operator == "-":
result = num1 - num2
elif operator == "*":
result = num1 * num2
elif operator == "/":
if num2 != 0:
result = num1 / num2
else:
print("Error: cannot divide by zero")
result = None
else:
print("Invalid operator")
result = None
if result is not None:
print("Result:", result)
| Mistake | Problem | Fix |
|---|---|---|
| Not casting input | "5" + "3" gives "53" (concatenation) | Use int(input()) for numbers |
| Concatenating string with number | "Score: " + 42 causes error | Use str(42) to convert |
| No prompt message | User does not know what to enter | Always include a clear prompt |
| Spelling errors in variable names | scroe instead of score | Check variable names carefully |
input().print().input() always returns a string — cast to int() or real()/float() for numbers.str() to convert numbers to strings for concatenation in output.OCR Exam Tip: When completing pseudocode in the exam, always include
int()orreal()aroundinput()when the value will be used in calculations. This is one of the most commonly penalised errors in the marking scheme.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.