Skip to content

← Final exam model papers

Final Exam Model Paper 3

Theory paper: 50 marksTime: 2 hours

Practical exam: 20 marksTime: 1 hour 30 minutes

All questions are compulsory.

A full practice run of the Grade 12 final exam: the theory paper (50 marks, 2 hours) and, below it, the practical exam (20 marks, 1 hour 30 minutes, at a computer, marked by the school). In the theory paper, work out on paper what each program does, as in the exam hall: its programs have no Run button. In the practical exam, the programs run on this page.

A practice paper by Science Playground, made to its own course’s grid; not an official exam paper.

Write your answers on paper first. Then open each answer and its marking scheme, and give yourself one mark for each point you got. In multiple choice, your first choice counts.

Section A

10 × 1 = 10

1. Choose the correct option for each of the following questions.

a.

What is a Turing machine made of?

Pick an answer to see why.

b.

Nirmala says her new tool “can look at any Python program and tell you, without running it, whether it will ever print the word password. We tested it on 1,000 programs and it was right every time.” Which judgment is right?

Pick an answer to see why.

c.

What does git revert do?

Pick an answer to see why.

d.

Which of these functions is pure?

Pick an answer to see why.

e.

In a content delivery network, what is an edge server?

Pick an answer to see why.

f.

A bank wants to change the software on all 400 of its app servers. Why does it change 4 servers first, wait and watch, and then change the rest in stages?

Pick an answer to see why.

g.

A wallet company’s accounts are spread over 9 shards by the rule “account number mod 9”. It adds a tenth shard and changes the rule to “account number mod 10”. About what share of the accounts must move to another shard?

Pick an answer to see why.

h.

In proof of work, what is the nonce?

Pick an answer to see why.

i.

Why can’t key exchange on its own keep Sita’s connection to her bank private, if Eve controls the café’s Wi-Fi?

Pick an answer to see why.

j.

A study app’s chatbot tells a lonely Grade 12 student in Bhaktapur, “I really care about you and I feel sad when you are away.” Her friend says, “It said so, so it must feel something.” Which judgment is best?

Pick an answer to see why.

Section B

8 × 3 = 24

Write short answers to the following questions.

2.
[3]

Rekha’s shop till works out bills in Reverse Polish notation. For 3 notebooks at Rs 120 and 2 pens at Rs 25, less a Rs 50 discount, it is given:

3 120 × 2 25 × + 50 −

  • i.Work it out with a stack: write the stack after each symbol.
  • ii.Write the same bill in ordinary (infix) notation.
  • iii.Write (500 − 120) × 2 in Reverse Polish notation.
Answer

i.

Symbol Stack after it
3 3
120 3, 120
× 360
2 360, 2
25 360, 2, 25
× 360, 50
+ 410
50 410, 50
− 360

The answer, the one number left, is Rs 360.

  • ii.3 × 120 + 2 × 25 − 50
  • iii.500 120 − 2 ×
Marking scheme
  • i. Numbers pushed; each operator pops two and pushes the result, with the stack at each step and the answer Rs 360.
  • ii. The infix 3 × 120 + 2 × 25 − 50.
  • iii. 500 120 − 2 ×.
3.
[3]

A cooperative in Baglung is having a savings app made. The tasks, their lengths and what each must wait for:

Task Weeks Waits for
Ask the members 2 nothing
Design the database 3 Ask the members
Design the screens 4 Ask the members
Write the program 5 both designs
Train the staff 2 Design the screens
Go live 1 Write the program, Train the staff
  • i.Find the critical path and the shortest time the project can take.
  • ii.How much float do “Design the database” and “Train the staff” have?
  • iii.“Design the database” takes 2 weeks longer than planned. What happens to the end date?
Answer
  • i.The longest chain: Ask the members (2) → Design the screens (4) → Write the program (5) → Go live (1): 12 weeks. (Through the database it is 2 + 3 + 5 + 1 = 11; through training, 2 + 4 + 2 + 1 = 9.)
  • ii.Design the database: 1 week. It can finish at week 5 or 6; writing the program can’t start before week 6 anyway. Train the staff: 3 weeks. It can finish at week 8, but going live starts only at week 11.
  • iii.It now takes 5 weeks and finishes at week 7, a week later than the screens, so writing the program starts at week 7 and the project ends at week 13: one week late. Its 1 week of float absorbed the first week of the delay.
Marking scheme
  • i. Critical path through the screens and the program, 12 weeks.
  • ii. Float: 1 week for the database design, 3 weeks for training.
  • iii. The project ends 1 week late (13 weeks), because 1 of the 2 weeks is taken by the float.
4.
[3]

Sushant’s shop program gives the wrong total for the month. Its function monthly_total(sales) loops over the sales, and each time calls price_with_vat(item), then adds the result to total.

  • i.Where would you put a breakpoint, and what would you watch each time the program stops there?
  • ii.At the line that calls price_with_vat, when would you use step into, and when step over?
  • iii.When the program is stopped inside price_with_vat, what does the call stack show?
Answer
  • i.On the line inside the loop that adds to total (or the line just after it). Each time it stops, look at total and the item in the variables, and check them against a total worked out by hand: the first stop where they differ shows the sale that goes wrong.
  • ii.Step into when you suspect price_with_vat itself (it may work out VAT wrongly): it goes inside the function, line by line. Step over when you trust it: it runs the whole call at once and stops at the next line, so you stay in monthly_total.
  • iii.The functions waiting, one inside another: price_with_vat on top, called from monthly_total, called from the main program, each with its own variables.
Marking scheme
  • i. A breakpoint in the loop, watching total (and the item) against values worked out by hand.
  • ii. Step into to follow the function’s own lines; step over to run it whole and stay in the caller.
  • iii. The chain of calls waiting, price_with_vat on top of monthly_total.
5.
[3]

At a cooperative, clerk 1 is moving Rs 2,000 from Hari’s account to Gita’s, and clerk 2, at the same moment, Rs 500 from Gita’s account to Hari’s. Each program locks the account it takes money from, then the account it pays into.

  • i.Explain how the two transactions can end in a deadlock.
  • ii.What does the database do when it finds one?
  • iii.What must the clerk’s program then do, and why is no money lost?
Answer
  • i.Clerk 1’s transaction locks Hari’s account and waits for Gita’s; clerk 2’s has locked Gita’s and waits for Hari’s. Each holds the lock the other needs, so neither can ever go on.
  • ii.It rolls one transaction back, releasing its locks, so the other can finish.
  • iii.Try the rolled-back transaction again. A rollback undoes every part of it (atomicity), so no money left one account without reaching the other; the second try simply does the whole transfer.
Marking scheme
  • i. Each transaction holds one account’s lock and waits for the other’s, so both wait for ever.
  • ii. The database rolls one of them back, freeing its locks.
  • iii. The program tries it again; the rollback undid it completely, so no money is lost.
6.
[3]

A school in Kavrepalanchok fitted a straight line to the data of 120 Grade 11 students, who studied between 0 and 20 hours a week at home:

marks = 30 + 2.5 × (hours of study a week), with r² = 0.36.

  • i.Say what the slope means, in words about the students.
  • ii.Say what r² = 0.36 means.
  • iii.Could the line be used to predict the marks of a student who studies 40 hours a week? Explain.
Answer
  • i.On average, students who study one hour more a week score 2.5 marks more. (It describes the students in the data; it doesn’t prove that the extra hour causes the marks.)
  • ii.The line accounts for 36% of the spread in marks; the other 64% comes from everything else (ability, the teacher, sleep, luck). Many points are far from the line.
  • iii.No. 40 hours is far outside the data (0 to 20 hours): an extrapolation. The line would say 30 + 2.5 × 40 = 130 marks, more than the full 100, which shows the line can’t be trusted there.
Marking scheme
  • i. 2.5 more marks, on average, for each extra hour a week.
  • ii. The line explains 36% of the spread in marks; the rest is other things.
  • iii. No: 40 hours is outside the data, an extrapolation (it would predict an impossible 130).
7.
[3]

A ward chair in Gorkha says: “Since our free evening classes began in 2079, the SEE pass rate at the ward’s school has risen from 48% to 61% in 2082. The classes work.” The school’s pass rates for every year were:

Year 2076 2077 2078 2079 2080 2081 2082
Pass rate 58% 60% 55% 48% 54% 57% 61%

Judge the claim, and say what evidence would be better.

Answer

The claim is weak. It starts from 2079, the worst year in the table: comparing 2082 with 2077 shows almost no change (60% to 61%), so the “rise” is mostly a return from one bad year, picked as the starting point (cherry-picking). The rates go up and down by several points from year to year anyway. And with no comparison, anything else that changed (new teachers, an easier paper, pass rates rising across the country) could explain it.
Better evidence: compare the change at this school with the change at similar schools in wards without the classes over the same years; compare students who went to the classes with similar students who didn’t; or, best, offer the places by lot and compare the two groups (a randomized trial). Report every year, not only the convenient ones.

Marking scheme
  • The starting year is the worst one (cherry-picking); against 2076–2078 there is little or no rise.
  • Year-to-year ups and downs, and other causes, aren’t ruled out without a comparison group.
  • Better evidence: comparison with schools or students without the classes (ideally chosen at random), with all the years shown.
8.
[3]

A ward office signs its tax clearance letters with a tiny RSA key: public key (n, e) = (77, 7), private power d = 43.

  • i.n = 7 × 11. Show that d = 43 is a correct private power.
  • ii.A letter’s hash, cut down to a number below 77, is 5, and the office’s signature on it is 26. Check the signature with the public key, by repeated squaring.
  • iii.A forger changes the letter, whose hash becomes 12, and keeps the signature 26. Will the check accept it? Why?
Answer
  • i.φ(n) = (7 − 1)(11 − 1) = 60, and 7 × 43 = 301 = 5 × 60 + 1: one more than a multiple of φ(n), so 43 undoes 7.
  • ii.Work out 26⁷ mod 77: 26² = 676 ≡ 60 (676 − 616); 26⁴ ≡ 60² = 3,600 ≡ 58 (3,600 − 3,542); 26⁷ = 26⁴ × 26² × 26 ≡ 58 × 60 × 26. 58 × 60 = 3,480 ≡ 15 (3,480 − 3,465); 15 × 26 = 390 ≡ 5 (390 − 385). It equals the hash, 5: the signature is good.
  • iii.No. The check still gives 26⁷ mod 77 = 5, which doesn’t equal the new hash, 12. To make a signature that fits the new hash, the forger would need the private power, 43.
Marking scheme
  • i. φ(77) = 60 and 7 × 43 = 301 = 5 × 60 + 1.
  • ii. 26⁷ mod 77 = 5 by repeated squaring, equal to the hash.
  • iii. Refused: 5 ≠ 12, and a new signature needs the private key.
9.
[3]

What is a moral agent, and what is a moral patient? Give an example of each, and say which question about a machine decides whether it could be a moral patient.

Answer
  • A moral agent is someone who can be held responsible for what they do: an adult person.
  • A moral patient is someone who can be wronged, whose suffering counts: a baby, a dog, and any adult too.
  • Whether a machine could be a moral patient depends on whether it can feel anything (consciousness), not on how clever it is.
Marking scheme
  • Moral agent: can be held responsible, with an example.
  • Moral patient: can be wronged, with an example.
  • For a machine, it depends on whether it feels (consciousness), not intelligence.

Section C

2 × 8 = 16

Write long answers to the following questions.

10.
[8]

For the inter-school robot contest in Kathmandu, a robot must drive along painted lines from the start, S, to the flag, G. These are the lines between junctions, with their lengths in meters:

Line Meters
S – A 5
S – B 5
S – H 4
S – K 5
A – B 8
A – C 4
A – H 7
B – D 7
B – K 5
C – G 9
D – G 4

The team’s program estimates the distance left from each junction to the flag by the straight line, rounded down to whole meters:

Junction S A B C D H K G
Estimate 10 7 8 5 3 13 12 0
  • i.Use A* to find the shortest way from S to G. Write a row for each junction taken: its distance so far + estimate, what changes, and the junctions waiting with their totals. (3)
  • ii.Write the route and its length. (1)
  • iii.Dijkstra’s algorithm would also find this route. Which junctions would it take that A* never took, and why did A* not need them? (2)
  • iv.A teammate multiplies every estimate by 3, “to make it faster”. Work out the route A* now gives. Is it still the shortest? Why? (2)
Answer

i. The total for a junction is its distance so far + its estimate; the junction with the smallest total is taken next.

Taken So far + estimate What changes Waiting, smallest total first
S 0 + 10 = 10 A 5 + 7 = 12, B 5 + 8 = 13, H 4 + 13 = 17, K 5 + 12 = 17: new A 12, B 13, H 17, K 17
A 5 + 7 = 12 C 9 + 5 = 14: new. B by A, 13: not shorter than 5. H by A, 12: not shorter than 4 B 13, C 14, H 17, K 17
B 5 + 8 = 13 D 12 + 3 = 15: new. K by B, 10: not shorter than 5 C 14, D 15, H 17, K 17
C 9 + 5 = 14 G 18 + 0 = 18: new D 15, H 17, K 17, G 18
D 12 + 3 = 15 G 12 + 4 = 16: shorter than 18, now from D G 16, H 17, K 17
G 16 + 0 = 16 the flag: stop

ii. 16 m, by S → B → D → G (G came from D, D from B, B from S). The way through A and C, which heads straight at the flag, is 18 m.

iii. Dijkstra’s algorithm takes junctions in order of distance from the start alone, so it takes H (4 m) and K (5 m) as well, before reaching G at 16. A* never took them: they lie behind the start, so their estimates are large, and their totals (17) were never smaller than the flag’s 16. The estimate kept the search pointed at the flag.

iv. With the estimates tripled: from S, A’s total is 5 + 21 = 26, B’s 5 + 24 = 29, K’s 5 + 36 = 41, H’s 4 + 39 = 43, so A is taken. From A, C’s total is 9 + 15 = 24, so C is taken; then G, at 18 + 0 = 18, is smaller than B’s 29, so G is taken: the route S → A → C → G, 18 m. It is not the shortest. The estimates are now too high (C’s is 15, but C is only 9 m from the flag), so the long line from C looked better than it was, and the way through B and D was never tried. A* is sure to be right only when the estimate is never more than the real distance left.

Marking scheme
  • i. Totals worked out as distance so far + estimate, and the smallest total taken each time.
  • i. The junctions taken in order: S, A, B, C, D, G.
  • i. G’s distance changed from 18 to 16 when D is taken.
  • ii. 16 m, by S → B → D → G.
  • iii. Dijkstra’s algorithm also takes H and K.
  • iii. Their large estimates (they are behind the start) kept their totals above the flag’s.
  • iv. Route S → A → C → G, 18 m: not the shortest.
  • iv. Because the estimates are now too high, more than the real distance left.
11.
[8]

A school in Jhapa marks attendance with a camera at the gate that recognizes students’ faces, from photos taken when each student enrolled. A student it doesn’t recognize is marked absent and the family gets an SMS. The municipality’s scholarship rule stops the scholarship of any student whose attendance falls below 80%. For one week, teachers checked every mark by hand: 1,000 student-days, of which 50 were real absences.

Marked absent Marked present
Really absent 48 2
Really present 57 893

Split by grade:

Absent, marked absent Absent, marked present Present, marked absent Present, marked present
Grades 1–3 (300 student-days) 15 0 42 243
Grades 4–10 (700 student-days) 33 2 15 650
  • i.Taking “absent” as the positive, work out the system’s accuracy, precision and recall. (3)
  • ii.For each group, work out the share of present students who were marked absent. Suggest why the youngest students are failed most. (2)
  • iii.Should the school use the system for the attendance that decides scholarships? Argue your case, and say what must change first, or how it must be used. (3)
Answer

i. TP = 48, FN = 2, FP = 57, TN = 893.

  • Accuracy = (48 + 893) ÷ 1,000 = 94.1%
  • Precision = 48 ÷ (48 + 57) = 48 ÷ 105 = 46%: more than half of the “absent” marks are wrong.
  • Recall = 48 ÷ (48 + 2) = 96%: it finds nearly every real absence.

ii. Grades 1–3: 42 of 285 present student-days, 14.7%. Grades 4–10: 15 of 665, 2.3%. A young child in school is marked absent about one day in seven, more than six times as often as an older student. A likely cause: young children’s faces change fast, and the system compares them with photos from enrollment, months or years old: the world has drifted away from the data it was given. (Smaller faces, or children who don’t stand still at the gate, could add to it.)

iii. One well-argued case (other conclusions earn marks with good reasons): Not for scholarships, as it is.

  • The cost of each mistake. A wrong “absent” costs a family a worrying SMS, and, through the 80% rule, it can stop a scholarship that keeps a child in school. Those mistakes fall mostly on the youngest children. 94.1% accuracy hides this, because most days are present days anyway.
  • What must change first. Retake the photos regularly (say, every term) for the youngest grades and measure again by grade; keep checking each group after release, since faces keep changing.
  • How it could be used. A teacher checks the “absent” list each morning before any SMS is sent or any record kept (human review); families can see the record and ask for a correction (appeal); no scholarship is stopped on the camera’s marks alone; the old register is kept ready if the numbers fall. A paper register, which the teacher already calls, may be cheaper and fairer for Grades 1–3.
Marking scheme
  • i. Accuracy 94.1%.
  • i. Precision 46%.
  • i. Recall 96%.
  • ii. Present but marked absent: 14.7% in Grades 1–3, 2.3% in Grades 4–10.
  • ii. A sensible cause: the enrollment photos are out of date for fast-changing young faces (drift).
  • iii. A clear conclusion argued from the cost of a wrong “absent” (an SMS and a lost scholarship), which falls on the youngest.
  • iii. The cause dealt with: new photos, measured by grade, checked after release.
  • iii. Safeguards: a teacher checks before any SMS or record, families can appeal, no scholarship decided by the camera alone.

Practical exam

20 marks

Marked by the school. Work alone at a computer, with no internet and no AI, in front of the teacher, for 1 hour 30 minutes. Write and run each program, show it working, and answer the teacher’s questions. On this page, press Edit on a program to type in it, and Run to run it.

P1.
[7]

Did you mean…? A shop’s stock search should suggest the item nearest to what a customer types. Write a function distance(a, b) that returns the edit distance between two words (the fewest letters inserted, deleted or changed), and suggest(typed, items) that returns the nearest item (the first in the list, if several are as near). Write automatic tests for both, run by a small test runner, with at least one test of two swapped letters. Show the tests passing, then print the suggestions for suagr, biskut and sope.

ITEMS = ["rice", "lentils", "sugar", "salt", "soap", "noodles", "biscuits", "tea", "oil"] def distance(a, b):    return 0 def suggest(typed, items):    return items[0] # Your tests here
Answer
ITEMS = ["rice", "lentils", "sugar", "salt", "soap", "noodles", "biscuits", "tea", "oil"]  def distance(a, b):    """The edit distance between a and b: the fewest inserts, deletes and changes."""    table = [[0] * (len(b) + 1) for _ in range(len(a) + 1)]    for i in range(len(a) + 1):        table[i][0] = i    for j in range(len(b) + 1):        table[0][j] = j    for i in range(1, len(a) + 1):        for j in range(1, len(b) + 1):            change = 0 if a[i - 1] == b[j - 1] else 1            table[i][j] = min(table[i - 1][j] + 1,           # delete                              table[i][j - 1] + 1,           # insert                              table[i - 1][j - 1] + change)  # keep or change    return table[len(a)][len(b)]  def suggest(typed, items):    """The item nearest to what was typed (the first of them if several are as near)."""    best = None    for item in items:        d = distance(typed, item)        if best is None or d < best[0]:            best = (d, item)    return best[1]  def test_empty():    assert distance("", "rice") == 4    assert distance("salt", "") == 4  def test_same():    assert distance("soap", "soap") == 0  def test_one_edit():    assert distance("nodles", "noodles") == 1      # insert o    assert distance("tee", "tea") == 1             # change e to a  def test_swap_costs_two():    assert distance("saop", "soap") == 2  def test_suggest():    assert suggest("nodles", ITEMS) == "noodles"    assert suggest("oyl", ITEMS) == "oil"  passed = failed = 0for name, test in list(globals().items()):    if name.startswith("test_"):        try:            test()            print("PASS", name)            passed += 1        except AssertionError as problem:            print("FAIL", name, problem)            failed += 1print(passed, "passed,", failed, "failed")for typed in ["suagr", "biskut", "sope"]:    print(typed, "→", suggest(typed, ITEMS), distance(typed, suggest(typed, ITEMS)))

Output

PASS test_emptyPASS test_samePASS test_one_editPASS test_swap_costs_twoPASS test_suggest5 passed, 0 failedsuagr → sugar 2biskut → biscuits 3sope → soap 2
Marking scheme
  • A table with the first row and column counting up, as the distance from an empty word.
  • Each other cell the smallest of above + 1, left + 1 and diagonal + 0 or 1 (dynamic programming).
  • suggest keeps the item with the smallest distance, the first one on a tie.
  • Tests written as test_ functions with assert, with answers worked out by hand.
  • A test of an empty word and a test of two swapped letters (2 edits).
  • A runner that runs every test and reports passes and failures; all pass.
  • Prints sugar, biscuits and soap.
P2.
[4]

The changed timetable. A school’s program makes each day’s list of periods from the usual timetable, with any changes for that day. Run the tests, find why one fails, fix the code, and run them again.

TIMETABLE = ["Nepali", "English", "Maths", "Science", "Social", "Computer"]  def day_plan(changes):    """Today's periods: the usual timetable with today's changes (period number: subject)."""    plan = TIMETABLE    for period, subject in changes.items():        plan[period] = subject    return plan  def test_no_changes():    assert day_plan({}) == ["Nepali", "English", "Maths", "Science", "Social", "Computer"]  def test_sports_day():    assert day_plan({2: "Sports"})[2] == "Sports"  def test_next_day_as_usual():    assert day_plan({})[2] == "Maths", f"period 2 is {day_plan({})[2]}"  passed = failed = 0for name, test in list(globals().items()):    if name.startswith("test_"):        try:            test()            print("PASS", name)            passed += 1        except AssertionError as problem:            print("FAIL", name, problem)            failed += 1print(passed, "passed,", failed, "failed")
Answer

The first run:

Output

PASS test_no_changesPASS test_sports_dayFAIL test_next_day_as_usual period 2 is Sports2 passed, 1 failed

After the sports day, the next day’s plan still has Sports in period 2. Line 6, plan = TIMETABLE, doesn’t copy the list: it gives the same list a second name, so line 8 changes the usual timetable itself, and every later day gets the change. Make a copy, so each day changes only its own list:

TIMETABLE = ["Nepali", "English", "Maths", "Science", "Social", "Computer"]  def day_plan(changes):    """Today's periods: the usual timetable with today's changes (period number: subject)."""    plan = list(TIMETABLE)          # a copy: the usual timetable stays as it is    for period, subject in changes.items():        plan[period] = subject    return plan  def test_no_changes():    assert day_plan({}) == ["Nepali", "English", "Maths", "Science", "Social", "Computer"]  def test_sports_day():    assert day_plan({2: "Sports"})[2] == "Sports"  def test_next_day_as_usual():    assert day_plan({})[2] == "Maths", f"period 2 is {day_plan({})[2]}"  passed = failed = 0for name, test in list(globals().items()):    if name.startswith("test_"):        try:            test()            print("PASS", name)            passed += 1        except AssertionError as problem:            print("FAIL", name, problem)            failed += 1print(passed, "passed,", failed, "failed")

Output

PASS test_no_changesPASS test_sports_dayPASS test_next_day_as_usual3 passed, 0 failed

(Keeping the usual timetable as a tuple, which can’t be changed, would also stop the mistake: line 8 would then fail at once instead of quietly changing it.)

Marking scheme
  • Runs the tests and names the failing one: the next day still has Sports in period 2.
  • Finds the cause: line 6 makes a second name for the same list, not a copy, so the usual timetable is changed.
  • Fixes it with a copy (list(TIMETABLE) or TIMETABLE[:]), not by changing the tests.
  • Runs all the tests again, and all pass.
P3.
[4]

The note checker. A shop in Birtamod tried a machine that says whether a banknote is fake. It was tested on 60 notes checked by a bank: truth has F where the note really was fake, said has F where the machine said fake, and note is 5 for a Rs 500 note and 1 for a Rs 1,000 note. (The notes and results are made up.)

Write a program that counts the four outcomes and works out the machine’s precision and recall, for all 60 notes and for the Rs 500 and Rs 1,000 notes apart. Then write one limit of the machine, in a sentence for the shopkeeper, with the numbers that show it.

truth = "--------------F-------F-------FFFF---F-F---F-F-----F-----F--"said  = "----F---------F------------F--FFFF---F-FF-----F----------F--"note  = "555151115155151515515515551511555551555555151115155151511115" # Your program here
Answer
truth = "--------------F-------F-------FFFF---F-F---F-F-----F-----F--"said  = "----F---------F------------F--FFFF---F-FF-----F----------F--"note  = "555151115155151515515515551511555551555555151115155151511115"  def measure(name, which):    """Counts the outcomes for the notes whose digit is in `which`."""    tp = fp = fn = tn = 0    for real, model, n in zip(truth, said, note):        if n not in which:            continue        if real == "F" and model == "F":            tp += 1        elif real == "F":            fn += 1        elif model == "F":            fp += 1        else:            tn += 1    precision = tp / (tp + fp)    recall = tp / (tp + fn)    print(f"{name:9} TP {tp}  FP {fp}  FN {fn}  TN {tn:2}  precision {precision:.0%}  recall {recall:.0%}")  measure("All", "51")measure("Rs 500", "5")measure("Rs 1,000", "1")

Output

All       TP 8  FP 4  FN 4  TN 44  precision 67%  recall 67%Rs 500    TP 6  FP 3  FN 1  TN 25  precision 67%  recall 86%Rs 1,000  TP 2  FP 1  FN 3  TN 19  precision 67%  recall 40%

One limit: “The machine caught 6 of 7 fake Rs 500 notes, but only 2 of 5 fake Rs 1,000 notes (40%), the notes that cost you most; and it was tested on only 12 fakes, too few to be sure of any of these numbers.” Until it is tested on many more fake Rs 1,000 notes, the shopkeeper should still check those by hand.

Marking scheme
  • A loop over the strings together that counts true positives, false positives, false negatives and true negatives.
  • Precision and recall worked out from the counts: 67% and 67% for all notes.
  • The Rs 500 and Rs 1,000 notes measured apart (recall 86% and 40%).
  • One limit stated in a sentence with its numbers (the Rs 1,000 recall, or only 12 fakes).
P4.
[5]

Viva. The teacher asks each student about their own work, for example:

  • i.In distance, what does each cell of your table hold, and why does the program never work out the same cell twice? (2)
  • ii.In the timetable program, why did the first two tests pass, though the bug was already there? (1)
  • iii.The note checker is right about 52 of the 60 notes, 87%. Why is that not enough to trust it with Rs 1,000 notes? What would you do? (2)
Answer
  • i.The cell in row i, column j holds the edit distance between the first i letters of one word and the first j letters of the other. Each cell is worked out once, from three cells already filled (above, left and diagonal), and kept in the table, so every smaller problem is solved once and reused: dynamic programming.
  • ii.They ran before the bug did any harm: the first test made no change, and the second only looked at the day it changed. The damage, a changed usual timetable, shows only on a later call, which is why a test of the next day was needed.
  • iii.Most of the notes are real, so a machine that called every note real would still be right about 48 of the 60 (80%). Accuracy hides that it missed 3 of the 5 fake Rs 1,000 notes. Test it on many more fake Rs 1,000 notes, measure each kind of note apart, and keep checking Rs 1,000 notes by hand until it does better.
Marking scheme
  • i. A cell is the distance between the first i letters of one word and the first j of the other.
  • i. Each cell is filled once from cells already worked out, and kept.
  • ii. The bug changed the usual timetable, which only a later day’s plan shows.
  • iii. Fakes are few, so a high accuracy can hide many missed fakes.
  • iii. Test on more fake Rs 1,000 notes, measure by kind, and check them by hand meanwhile.

Your score

0 / 50 theory

0 / 20 practical

24 questions not marked yet

Section A–Full marks 10
Section B–Full marks 24
Section C–Full marks 16
Practical exam–Full marks 20

Marks lost, by unit

Mark a question to see your score here.

Score 0 of 0 0 of 24 marked Time left: 2:00:00