You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
One of the most challenging question types in OCR J277 Paper 2 asks you to write a program (or section of code) based on a given specification. These questions typically carry 4-8 marks and test your ability to translate a problem description into working code.
Follow this systematic approach:
OCR Exam Tip: You can use either OCR pseudocode or Python. The mark scheme accepts both. Choose whichever you are more comfortable with, but be consistent within your answer.
Specification: Ask the user to enter a number between 1 and 100. Keep asking until a valid number is entered.
// OCR pseudocode
do
num = int(input("Enter a number between 1 and 100: "))
until num >= 1 AND num <= 100
print("You entered: " + str(num))
# Python
num = int(input("Enter a number between 1 and 100: "))
while num < 1 or num > 100:
num = int(input("Enter a number between 1 and 100: "))
print("You entered:", num)
Specification: Ask the user to enter 10 test scores. Calculate and display the total and average.
// OCR pseudocode
total = 0
for i = 1 to 10
score = int(input("Enter score: "))
total = total + score
next i
average = total / 10
print("Total: " + str(total))
print("Average: " + str(average))
# Python
total = 0
for i in range(10):
score = int(input("Enter score: "))
total += score
average = total / 10
print("Total:", total)
print("Average:", average)
Specification: Search an array of names for a given name and report whether it was found.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.