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 provides comprehensive exam practice for the Programming Fundamentals topic, covering the key content from OCR J277 Section 2.3 that appears on Paper 2: Computational Thinking, Algorithms and Programming. This lesson brings together all programming concepts: variables, data types, operators, selection, iteration, arrays, strings, subroutines, and file handling.
Paper 2 is worth 80 marks and lasts 1 hour 30 minutes. Programming fundamentals typically accounts for 25–35 marks. Questions will use OCR pseudocode and/or Python.
| Question Type | Typical Marks | What You Need to Do |
|---|---|---|
| Identify data type | 1 mark | Name the data type of a given value |
| Explain a keyword | 1–2 marks | Define a programming term |
| Read and interpret code | 2–4 marks | State the output of given code |
| Complete/fix code | 3–5 marks | Fill in blanks or correct errors |
| Write a program | 4–8 marks | Write a complete solution from a description |
| Explain benefits | 2–3 marks | Justify a programming choice |
OCR Exam Tip: You may answer Paper 2 questions using either OCR pseudocode or Python. Be consistent — do not mix them within a single answer. If you are stronger in Python, use Python throughout.
Question: State the most appropriate data type for each of the following: (a) The number of students in a class (b) Whether a light switch is on or off
Model Answer: (a) Integer — the number of students is always a whole number. (b) Boolean — there are only two possible states: true (on) or false (off).
Question: What are the values of the following expressions?
(a) 27 DIV 5
(b) 27 MOD 5
(c) 100 MOD 7
Model Answer:
(a) 27 DIV 5 = 5 (27 divided by 5 is 5 remainder 2; DIV gives the quotient)
(b) 27 MOD 5 = 2 (27 divided by 5 is 5 remainder 2; MOD gives the remainder)
(c) 100 MOD 7 = 2 (100 = 7 × 14 + 2; the remainder is 2)
Question: Complete a trace table for the following pseudocode:
x = 10
y = 3
while x > 0
x = x - y
y = y + 1
endwhile
print(x)
Model Answer:
| Step | x | y | x > 0? |
|---|---|---|---|
| Init | 10 | 3 | true |
| 1 | 7 | 4 | true |
| 2 | 3 | 5 | true |
| 3 | -2 | 6 | false |
Output: -2
Question: What is the output of the following code?
word = "COMPUTING"
x = word.length
y = word.substring(0, 4)
z = word.substring(4, x)
print(y.lower + " " + z)
Model Answer:
x = 9 (length of "COMPUTING")y = "COMP" (characters at indices 0, 1, 2, 3)z = "UTING" (characters at indices 4, 5, 6, 7, 8)y.lower = "comp"Question: Write a function called isEven that takes an integer as a parameter and returns true if the number is even, or false if it is odd.
OCR Pseudocode:
function isEven(number)
if number MOD 2 == 0 then
return true
else
return false
endif
endfunction
Python:
def is_even(number):
if number % 2 == 0:
return True
else:
return False
The decision flow for this function can be visualised as a simple validation flowchart:
flowchart TD
A([Start: isEven called with number]) --> B[Compute number MOD 2]
B --> C{Result == 0?}
C -->|Yes| D[return true]
C -->|No| E[return false]
D --> F([End])
E --> F
Question: Write a program that stores 5 names in an array, then asks the user for a name and searches for it using a linear search. Display whether the name was found and at which index.
OCR Pseudocode:
names = ["Ali", "Beth", "Cara", "Dan", "Eve"]
target = input("Enter a name to search for: ")
found = false
for i = 0 to names.length - 1
if names[i] == target then
print("Found at index " + str(i))
found = true
endif
next i
if found == false then
print("Name not found")
endif
Python:
names = ["Ali", "Beth", "Cara", "Dan", "Eve"]
target = input("Enter a name to search for: ")
found = False
for i in range(len(names)):
if names[i] == target:
print(f"Found at index {i}")
found = True
if not found:
print("Name not found")
Question: Write pseudocode that reads all lines from a file called "scores.txt", where each line contains a number. Calculate and display the total and average of all scores.
OCR Pseudocode:
myFile = openRead("scores.txt")
total = 0
count = 0
while NOT myFile.endOfFile()
line = myFile.readLine()
score = int(line)
total = total + score
count = count + 1
endwhile
myFile.close()
if count > 0 then
average = total / count
print("Total: " + str(total))
print("Average: " + str(average))
else
print("No scores found")
endif
Python:
total = 0
count = 0
with open("scores.txt", "r") as my_file:
for line in my_file:
score = int(line.strip())
total += score
count += 1
if count > 0:
average = total / count
print(f"Total: {total}")
print(f"Average: {average}")
else:
print("No scores found")
Question: A school needs a program to calculate student grades. Write: (a) A function that takes a mark (0–100) and returns the grade (A: 70+, B: 60–69, C: 50–59, U: below 50). (b) A procedure that takes a student name and mark, uses the function, and displays the result.
OCR Pseudocode:
function getGrade(mark)
if mark >= 70 then
return "A"
elseif mark >= 60 then
return "B"
elseif mark >= 50 then
return "C"
else
return "U"
endif
endfunction
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.