You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
OCR J277 Paper 2 requires you to read, write, and trace code. OCR provides a reference language (pseudocode) that appears in exam questions. You must be familiar with its syntax. This lesson covers the key constructs of OCR pseudocode and strategies for answering code-based questions.
The OCR reference language is a pseudocode that looks similar to Python but has some differences. You can answer Paper 2 questions using either OCR pseudocode or a high-level language like Python. However, you must understand OCR pseudocode because the exam questions use it.
The decision flow below shows how to choose between OCR pseudocode and Python under exam conditions, and how the choice cascades through control structures:
flowchart TD
A[Read code question] --> B{Does question show OCR pseudocode?}
B -->|Yes| C[Stick with OCR pseudocode]
B -->|No, open ended| D{More confident in Python?}
D -->|Yes| E[Write Python with colons + indentation]
D -->|No| C
C --> F[Use then/endif, next, endwhile, endfunction]
E --> G[Use : and indentation, no closing keywords]
F --> H[Use lowercase true/false and MOD]
G --> I[Use True/False and %]
H --> J[Stay consistent throughout answer]
I --> J
// OCR pseudocode
name = "Alice"
age = 16
score = 0.0
isStudent = true
# Equivalent Python
name = "Alice"
age = 16
score = 0.0
is_student = True
Key difference: OCR pseudocode uses lowercase true and false.
// OCR pseudocode
name = input("Enter your name: ")
print("Hello " + name)
# Equivalent Python
name = input("Enter your name: ")
print("Hello " + name)
These are essentially identical in OCR pseudocode and Python.
// OCR pseudocode
if score >= 50 then
print("Pass")
elseif score >= 40 then
print("Near miss")
else
print("Fail")
endif
# Equivalent Python
if score >= 50:
print("Pass")
elif score >= 40:
print("Near miss")
else:
print("Fail")
| OCR pseudocode | Python |
|---|---|
if ... then | if ...: |
elseif | elif |
endif | (indentation ends the block) |
OCR Exam Tip: In OCR pseudocode, every
ifmust have a matchingendif. Everyformust have a matchingnext. Everywhilemust have a matchingendwhile. Missing these closing keywords will lose marks.
// OCR pseudocode
for i = 1 to 10
print(i)
next i
# Equivalent Python
for i in range(1, 11):
print(i)
Key difference: OCR for i = 1 to 10 includes both 1 and 10. Python range(1, 11) includes 1 but excludes 11. The result is the same.
// OCR pseudocode
password = ""
while password != "secret"
password = input("Enter password: ")
endwhile
print("Access granted")
# Equivalent Python
password = ""
while password != "secret":
password = input("Enter password: ")
print("Access granted")
// OCR pseudocode
do
password = input("Enter password: ")
until password == "secret"
print("Access granted")
Python does not have a built-in do-while, but you can simulate it:
while True:
password = input("Enter password: ")
if password == "secret":
break
print("Access granted")
OCR Exam Tip: The key difference between
whileanddo...untilis thatdo...untilalways runs at least once because the condition is checked at the end. Thewhileloop checks the condition first, so it may not run at all.
// OCR pseudocode
names = ["Alice", "Bob", "Charlie"]
print(names[0]) // Outputs: Alice
names[1] = "Ben"
# Equivalent Python (using a list)
names = ["Alice", "Bob", "Charlie"]
print(names[0]) # Outputs: Alice
names[1] = "Ben"
OCR uses zero-based indexing (the first element is at index 0).
| Operation | OCR pseudocode | Python |
|---|---|---|
| Length | name.length | len(name) |
| Substring | name.substring(0, 3) | name[0:3] |
| Upper case | name.upper | name.upper() |
| Lower case | name.lower | name.lower() |
| ASCII value | ASC("A") | ord("A") |
| Char from ASCII | CHR(65) | chr(65) |
// OCR pseudocode — procedure (no return value)
procedure greet(name)
print("Hello " + name)
endprocedure
greet("Alice")
// OCR pseudocode — function (returns a value)
function double(x)
return x * 2
endfunction
result = double(5)
print(result)
# Equivalent Python
def greet(name):
print("Hello " + name)
greet("Alice")
def double(x):
return x * 2
result = double(5)
print(result)
// OCR pseudocode — reading a file
myFile = openRead("data.txt")
line = myFile.readLine()
myFile.close()
// OCR pseudocode — writing to a file
myFile = openWrite("output.txt")
myFile.writeLine("Hello World")
myFile.close()
# Equivalent Python
with open("data.txt", "r") as f:
line = f.readline()
with open("output.txt", "w") as f:
f.write("Hello World\n")
total_score not xOCR Exam Tip: You can answer in either OCR pseudocode or Python (or any high-level language). Choose whichever you are most confident with. Be consistent — do not mix languages within a single answer.
then/endif, next, endwhile, endprocedure, endfunctionA common Paper 2 question gives you pseudocode and asks you to rewrite it in a high-level language, or vice versa. Translating accurately under time pressure takes practice — here is a worked walkthrough showing how to approach a typical 6-mark translation question.
Question: "The following OCR pseudocode reads 5 numbers and displays how many are even. Rewrite it in Python." (6 marks)
OCR pseudocode:
count = 0
for i = 1 to 5
num = int(input("Enter number: "))
if num MOD 2 == 0 then
count = count + 1
endif
next i
print(str(count) + " numbers were even")
Step 1 — Identify the key translations. Use a small mapping table:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.