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.
// 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")
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.