This post works through 2026 Paper II, B, Q9, a library fine question that joins three levels of Unit 9: functions (9.9), data structures (9.10) and sequential search (9.13). The same question shape came in 2024, 2025 and 2026, so the method here is the method for the next paper too.
The post has three parts:
- The question: what it asks, the three-year pattern behind it, and the fine rule that says two different things (sections 1 and 2).
- The answers: the function in part (a), the list of tuples in part (b), the search in part (c) and the trace in part (d) (sections 3 to 5).
- Beyond Q9: lists and tuples inside functions in Paper I, and past paper questions to try (sections 6 and 7).
1. What 2026 Paper II Q9 asks
Q9 gives a library's late returns as a list of tuples and asks four things: a function, a new list, a search function and a trace. Each record is a tuple (memberNo, lateDays), and all the records are in one list, lateReturns (G.C.E. (A/L) 2026 ICT Paper II, Sinhala medium, pages 12 and 13).
The four parts carry 15 marks:
- (a), 5 marks: write
calculateFine(lateDays), which returns the fine for one member. - (b), 4 marks: build
fineList, a new list of(memberNo, fine)tuples for the members who must pay. - (c), 4 marks: write
searchFine(fineList, memberNo)with a sequential search. It returns the fine, or -1 when the member is not in the list. - (d), 2 marks: write the output of three
calculateFinecalls and onesearchFinecall.
The same shape three years in a row
Python moved from Paper II, Part B, Q8 to Q9 in 2026, but the building blocks stayed the same. Learn them as one set.
- 2024 Paper II, B, Q8(c) builds a list of tuples with a list comprehension, sorts it with
key=lambda x: x[0], and loops over it withfor value, weight, name, index in merged. Our own worked answer for the nine labels: An, Bweights, Cres, Dres, Eremainder, Fremainder, Gweight, Hitem_selector, Iselected. - 2025 Paper II, B, Q8 asks a function that returns a tuple and a sentinel loop that fills a list of tuples. Its last part searches the list and prints one student's marks. The official answer to 2025 Paper II, B, Q8(b) is one line:
return indexNumber, mark1, mark2, mark3. The commas alone make the tuple. - 2026 Paper II, B, Q9 asks all of these in one question, and adds a "not found" value to the search.
The official 2025 scheme gives marks for each part of the code: the def line, the loop, the if and the output. It also says "Codes with the same functionality are acceptable." So a correct program in a different style still gets the marks.
Across the eight new-syllabus papers, 2019 to 2026, functions (9.9) hold 10 MCQs and 20.5 Paper II marks, in all eight papers. Data structures (9.10) hold 9 MCQs and 34 Paper II marks, in seven papers. Sequential search and bubble sort (9.13) hold 9 Paper II marks, all in 2023 (held 2024) and 2026.
2. The fine rule and its two readings
The fine rule in Q9 can be read in two ways, and the two readings give different fines for more than 10 days. Here is our English translation of the paper's table:
- 0 to 5 days: no fine.
- 6 to 10 days: Rs. 10 for each day after the first 5 days.
- More than 10 days: Rs. 10 a day for the first 5 days, and Rs. 25 a day for the remaining days.
- Maximum fine: Rs. 500.
The paper then gives one example: "if lateDays = 12, the fine is (5 × 10) + (7 × 25) = 225" (G.C.E. (A/L) 2026 ICT Paper II, Sinhala medium, page 12).
Reading 1 is the worked example
The example charges Rs. 25 for every day after day 5. For 12 days, that is 5 days at Rs. 10 and 7 days at Rs. 25, which is 225. In code, the third branch is 5 * 10 + (lateDays - 5) * 25.
Reading 2 is the table alone
The 6 to 10 row makes the first 5 days free. So "the first 5 days" at Rs. 10 can only mean days 6 to 10, and the "remaining days" start at day 11. For 12 days, that is 50 + 2 × 25 = 100. In code, the third branch is 5 * 10 + (lateDays - 10) * 25.
Two facts support the table reading:
- With the example's rule, the fine jumps from Rs. 50 at 10 days to Rs. 200 at 11 days. One more late day costs Rs. 150.
- Part (d) searches a list that holds the fine 125. With the table, 13 days gives 125. With the example, no number of days gives 125.
But the example is the only place where the paper shows the rule with numbers. This post follows the example in its answers, and gives the table result next to it each time.
3. calculateFine with if and elif
Part (a) needs a function that takes the late days as a parameter, chooses one branch with if and elif, applies the maximum, and returns the fine. The Resource Book defines a function as "a block of code which only runs when it is called". It uses return to send a value back (Resource Book 9.9, pages 53 and 54) (Resource Book 9.9, පිටු 59 සහ 60). The syllabus lists parameter passing, return values and default values under user defined functions (Syllabus 9.9, page 39) (විෂය නිර්දේශය 9.9, පිටුව 36).
Our own worked answer, with the worked example's rule:
def calculateFine(lateDays):
if lateDays <= 5:
fine = 0
elif lateDays <= 10:
fine = (lateDays - 5) * 10
else:
fine = 5 * 10 + (lateDays - 5) * 25
if fine > 500:
fine = 500
return fine
For the table reading, change only the else line to fine = 5 * 10 + (lateDays - 10) * 25.
Four places where marks are lost
- The order of the tests.
elif lateDays <= 10is True only whenlateDays <= 5was False. So the second branch needs nolateDays >= 6. If the tests come in the other order, 3 days falls into the 10-day branch and gives -20. - return, not print. Part (b) uses the fine in a calculation. A function that prints the fine returns
None, andNone > 0stops the program with an error. - The maximum. Apply the Rs. 500 limit after the branches.
fine = min(fine, 500)does the same job in one line. - The parameter name. Use
lateDaysinside the function, not a fixed number or a global variable. The callcalculateFine(15)must work for any number.
Trace the first three calls of part (d)
calculateFine(4): 4 is 5 or less, so the output is0.calculateFine(7): 7 is 10 or less, so (7 - 5) × 10 gives20.calculateFine(15): with the worked example, 50 + 10 × 25 gives300. With the table, 50 + 5 × 25 gives175. Both are under the maximum.
4. fineList from a list of tuples
Part (b) needs a loop over lateReturns that calls calculateFine for each record and adds a new tuple only when the fine is more than 0. A list is "ordered and changeable" and uses square brackets. A tuple is ordered but "unchangeable (immutable)" and uses round brackets (Resource Book 9.10, pages 56 and 59) (Resource Book 9.10, පිටු 62 සහ 65). The Sinhala Resource Book calls them "ලැයිස්තුව" and "ටපලය", the words the Sinhala paper uses.
Our own worked answer:
lateReturns = [("M001", 1), ("M002", 5), ("M003", 10), ("M004", 20), ("M005", 30)]
fineList = []
for memberNo, lateDays in lateReturns:
fine = calculateFine(lateDays)
if fine > 0:
fineList.append((memberNo, fine))
print(fineList)
With the worked example's rule, fineList is [("M003", 50), ("M004", 425), ("M005", 500)]. With the table, M004 gets 300 instead of 425. M001 and M002 have 1 and 5 late days, so their fine is 0, and they are left out. M005 has 30 days, so the fine stops at the Rs. 500 maximum.
Three details in the loop
- Unpack the tuple in the for line.
for memberNo, lateDays in lateReturnsgives each part a name.for record in lateReturnswithrecord[0]andrecord[1]is also right. - Two brackets in append.
appendtakes one item, and here the item is a tuple. So writefineList.append((memberNo, fine)).fineList.append(memberNo, fine)stops with a TypeError. - Start with an empty list.
fineList = []comes before the loop. If it is inside the loop, the list empties on every pass.
A list comprehension, the form of 2024 Paper II, B, Q8(c), gives the same list in one line:
fineList = [(m, calculateFine(d)) for m, d in lateReturns if calculateFine(d) > 0]
The tuples in fineList cannot change, but the list can. To change M004's fine, replace the whole tuple: fineList[1] = ("M004", 300). The line fineList[1][1] = 300 stops with a TypeError, the error the Resource Book shows for a tuple (Resource Book 9.10, page 59) (Resource Book 9.10, පිටුව 65).
5. searchFine as a sequential search
A sequential search checks the items one by one from the start, returns as soon as one matches, and reports "not found" only after the loop ends. The Teachers' Guide asks students to search "a data set stored in an array" with this method (Teachers' Guide 9.13, page 84) (ගුරු අත්පොත 9.13, පිටුව 83). The Sinhala books call it "අනුක්රමික සෙවුම", the word in the Sinhala paper.
Our own worked answer for part (c):
def searchFine(fineList, memberNo):
for record in fineList:
if record[0] == memberNo:
return record[1]
return -1
The return record[1] inside the loop ends the function at the first match. The return -1 runs only when the loop ends with no match. A fine is never negative, so -1 cannot be mistaken for a real fine. It is the same idea as the sentinel value in a while loop.
The trap is return -1 inside the loop
If return -1 sits in an else under the if, the function returns on the first record, match or not. With fineList = [("M003", 50), ("M004", 425), ("M005", 500)], the search for M004 checks M003, takes the else, and returns -1. Only the first member can ever be found. A flag gives the same result as the correct version. Set found = False before the loop, set it to True on a match, and test it after the loop. The flag method is in Python loop tracing with trace tables.
The last call of part (d)
searchFine([("M002", 30), ("M003", 125), ("M005", 500)], "M003") checks M002, then finds M003 and returns 125. This call does not use calculateFine. It only reads the number in the list. So the full output of part (d) is 0, 20, 300 and 125, each on its own line. With the table reading, the third line is 175.
6. Lists and tuples inside functions in Paper I
Paper I tests the same ideas in short code: a list passed to a function, a copy of a list, and the brackets of each data structure. The Teachers' Guide asks students to "identify the data structures Strings, Lists, Tuples, Dictionaries used in a sample program" (Teachers' Guide 9.10, page 81) (ගුරු අත්පොත 9.10, පිටුව 80).
A list passed to a function is the same list
2026 Paper I, Q37 passes stock = [5, 10, 15] to two functions. update sets item 1 to 50. restock adds 10 to items 0 and 1, from range(2). The answer is [15, 60, 15], option (3), our own worked answer. Option (1) assumes that the function works on a copy. Option (4) reads range(2) as three items.
The copy method and the brackets of each structure
- 2026 Paper I, Q38:
record["ICT"]starts atstudent[2], which is 20, and becomes 70.copy()makes a new list, soclear()andappend(100)change onlynew_list. The answer is['Saman', 70] [100], option (1), our own worked answer. Option (2) usesstudent[1], which is 17. - 2026 Paper I, Q39: the brackets name the structure.
"My Name"is a string,[10, 20, 30]a list,(10, 20, 30)a tuple and{"B": 85, "A": 90}a dictionary. The answer is A 4, B 1, C 3, D 2, option (4), our own worked answer. - 2025 Paper I, Q36:
(1,2,3)[-1]is the last item, 3. Multiplication comes first, so 3 + 12 gives 15, option (2), the official key.
7. Past paper questions to try
Try each question with the method of its section, then check the answer given there. Questions without an answer in this post are for practice.
- Functions (section 3): 2019 (New Syllabus) Paper I, Q48, 2020 Paper I, Q38, 2021 (held 2022) Paper I, Q42, 2022 (held 2023) Paper I, Q38, Q39 and Q42, 2022 (held 2023) Paper II, B, Q8(b), 2023 (held 2024) Paper I, Q40 and Q41, 2023 (held 2024) Paper II, A, Q3(c), 2024 Paper I, Q40, 2024 Paper II, A, Q3(b), 2025 Paper II, B, Q8(a).
- Lists, tuples and dictionaries (sections 4 and 6): 2020 Paper I, Q36 and Q37, 2020 Paper II, A, Q2(b), 2021 (held 2022) Paper I, Q43, 2022 (held 2023) Paper I, Q40, 2023 (held 2024) Paper I, Q42 and Q44, 2025 Paper I, Q36, 2026 Paper I, Q37, Q38 and Q39.
- Lists of tuples in Paper II (sections 1 and 4): 2024 Paper II, B, Q8(c), 2025 Paper II, B, Q8(b) and (c), 2026 Paper II, B, Q9(a), (b) and (d).
- Search and sort (section 5): 2023 (held 2024) Paper II, B, Q8(b), 2025 Paper II, B, Q8(d), 2026 Paper II, B, Q9(c).
The old-syllabus papers asked the same skills. Try these for more practice.
- 2012 Paper I, Q49: a function that returns the index of the largest item in a list.
- 2015 Paper I, Q46: a function that returns a tuple.
- 2018 Paper II, B, Q4(b)(ii): the purpose of a sequential search.
