S4 ICT Practice Paper: Programming and Algorithm Fundamentals
- 2026-11-09
S4 ICT practice paper on operator precedence, while loops, conditionals, linear and binary search, bubble sort, functions, strings, loop efficiency and debugging. 12 questions, 100 marks.
Section A: Operators, Loops and Conditionals (28 marks)
Questions 1-4: Operator Precedence and Integer Division, While-Loop Tracing, If-Elif-Else, Linear vs Binary Search
| # | Question | Answer and marking notes |
|---|---|---|
| 1 |
A program uses integer variables a and b, where a = 87 and b = 12. (a) State the results of the Python expressions a // b, a % b and a / b, giving a / b correct to 2 decimal places. (3 marks) |
(a) 87 // 12 = 7 (integer quotient); 87 % 12 = 3 (remainder, since 12 x 7 = 84); 87 / 12 = 7.25 (true division). (3 marks) |
| 2 |
Consider the following Python code: total = 0;
i = 1;
while i <= 8:
total = total + i * i
i = i + 2
(a) Complete a trace table showing i and total after each iteration. (4 marks) |
(a) Trace: i = 1 gives total = 1; i = 3 gives total = 10; i = 5 gives total = 35; i = 7 gives total = 84; then i = 9, the condition 9 is not at most 8, so the loop ends. (4 marks) |
| 3 |
The following code prints a grade for a score: if score >= 85:
grade = "A"
elif score >= 70:
grade = "B"
elif score >= 50:
grade = "C"
else:
grade = "F"
(a) State the output when score is 85, 84, 70 and 49. (4 marks) |
(a) 85 gives A; 84 gives B; 70 gives B; 49 gives F. (4 marks) |
| 4 |
A telephone directory has 2,000 records sorted by name. A program may use linear search or binary search. (a) State the number of comparisons for linear search in the worst case and in the average case. (2 marks) |
(a) Linear search needs 2000 comparisons in the worst case (item last or absent) and about 1000.5 on average, i.e. (n + 1) / 2. (2 marks) |
Section B: Sorting, Functions and Data Structures (32 marks)
Questions 5-8: Bubble Sort Tracing, Function Parameters, List Statistics, String Handling
| # | Question | Answer and marking notes |
|---|---|---|
| 5 |
The following code sorts a list in ascending order using bubble sort: data = [45, 12, 78, 33, 56, 90] (a) Write the list after the first pass. (4 marks) |
(a) Compare adjacent items left to right: 45 and 12 swap; 45 and 78 stay; 78 and 33 swap; 78 and 56 swap; 78 and 90 stay. Result [12, 45, 33, 56, 78, 90], with the largest value 90 now last. (4 marks) |
| 6 |
A function computes a tutorial fee of 120 per hour with a cap of 1,000 per session: def lesson_fee(hours, rate=120, cap=1000):
amount = hours * rate
if amount > cap:
amount = cap
return amount
(a) State the values returned by lesson_fee(6), lesson_fee(10) and lesson_fee(8.5). (3 marks) |
(a) lesson_fee(6) = 6 x 120 = 720; lesson_fee(10) = 1,200 which exceeds the cap, so 1000; lesson_fee(8.5) = 1,020, also capped to 1000. (3 marks) |
| 7 |
The test marks of 7 students are: marks = [72, 58, 91, 64, 85, 47, 79] (a) State the total, the highest mark and the lowest mark. (3 marks) |
(a) Total = 72 + 58 + 91 + 64 + 85 + 47 + 79 = 496; highest 91; lowest 47. (3 marks) |
| 8 |
A string variable s holds “Programming”. (a) State the values of len(s), s[0:4] and s[-3:]. (3 marks) |
(a) len(s) = 11; s[0:4] = Prog (indexes 0 to 3); s[-3:] = ing (last three characters). (3 marks) |
Section C: Efficiency, Debugging and Search Implementation (40 marks)
Questions 9-12: Nested-Loop Complexity, Debugging Logic Errors, Binary Search Tracing, Integrated Program
| # | Question | Answer and marking notes |
|---|---|---|
| 9 |
The following code counts the work done by nested loops: total = 0
for i in range(n):
for j in range(i):
total = total + 1
(a) What is total when n = 120? (3 marks) |
(a) The outer loop runs i = 0 to 119 and the inner loop runs i times, so total = 0 + 1 + … + 119 = 119 x 120 / 2 = 7140. (3 marks) |
| 10 |
The following program should sum all even numbers from 2 to 20 inclusive, but it is faulty: total = 0
i = 1
while i <= 20:
if i % 2 == 1:
total = total + i
i = i + 1
print(total)
(a) State the value the program actually prints. (2 marks) |
(a) The test keeps odd values (i % 2 == 1), so the program sums 1 + 3 + … + 19 = 100. (2 marks) |
| 11 |
The list below is sorted in ascending order; the program searches for key with binary search: ids = [12, 18, 23, 27, 31, 38, 44, 50, 56, 62, 69, 75, 81, 88, 94] (a) For key = 75, write low, high, mid and the comparison at each step, and give the final index. (5 marks) |
(a) low = 0, high = 14, mid = 7 gives ids[7] = 50, which is less than 75, so low = 8; then low = 8, high = 14, mid = 11 gives ids[11] = 75, a match at index 11. (5 marks) |
| 12 |
A program takes the marks of 8 students: scores = [48, 67, 55, 90, 73, 38, 81, 59] (a) Calculate the mean, correct to 1 decimal place. (3 marks) |
(a) Total = 48 + 67 + 55 + 90 + 73 + 38 + 81 + 59 = 511; mean = 511 / 8 = 63.875, i.e. 63.9. (3 marks) |
Find a tutor — freeTutor Registration →
A TutorZone practice paper; original questions and passages, not publisher material.


