Skip to content

← Final exam model papers

Final Exam Model Paper 1

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.

When is a problem in NP?

Pick an answer to see why.

b.

A company says its new app “checks any program a student writes, and always tells you correctly whether it will run for ever or stop.” Which judgment is right?

Pick an answer to see why.

c.

What is a regression?

Pick an answer to see why.

d.

On two branches, Nabin and Pooja each changed the same line of fees.py in a different way. What happens when Pooja merges Nabin’s branch into hers?

Pick an answer to see why.

e.

Which ACID property means that a transaction happens completely or not at all?

Pick an answer to see why.

f.

A cooperative keeps three copies of its accounts, in Dhangadhi, Nepalgunj and Butwal. A network partition cuts the Dhangadhi copy off from the other two. A member in Dhangadhi tries to withdraw Rs 5,000, and the screen says “Please try again later.” What has the system chosen?

Pick an answer to see why.

g.

A wallet app’s server needs 0.2 s to answer a request when nothing is waiting. Using time per request = time to serve one ÷ (1 − utilization), about how long does a request take when the server is 90% busy?

Pick an answer to see why.

h.

What is a certificate, as a browser uses it?

Pick an answer to see why.

i.

A school sends each student’s term grade, one of A, B, C, D or E, to the family as a number encrypted with textbook RSA and the school’s public key. Why can a classmate who copies the messages still read every grade?

Pick an answer to see why.

j.

A company’s drone carrying medicine crashes into a house in Dolakha. A software fault that the company had known about for months was the cause. The company blames the operator, who was watching twelve drones at once from Kathmandu. Which judgment is right?

Pick an answer to see why.

Section B

8 × 3 = 24

Write short answers to the following questions.

2.
[3]

A municipality pays flood relief to a list of households, and checks first that no citizenship number is on the list twice:

def has_repeat(numbers):    for i in range(len(numbers)):        for j in range(i + 1, len(numbers)):            if numbers[i] == numbers[j]:                return True    return False
  • i.What is the big O of this function? Give a reason.
  • ii.For 5,000 numbers it takes 2 seconds. About how long would it take for 5 lakh numbers?
  • iii.Why would a computer twice as fast not solve the problem?
Answer
  • i.**O(n²)**: a loop inside a loop, each going through the list, so it compares every pair, about n² ÷ 2 comparisons.
  • ii.5 lakh is 100 times 5,000, so the work grows 100 × 100 = 10,000 times: 2 × 10,000 = 20,000 seconds, about 5½ hours.
  • iii.A faster computer divides the time by a fixed number, here 2 (about 2¾ hours), while the work grows with the square of the list: ten times more numbers again would take a hundred times longer. Only a better algorithm changes how the work grows (for example, keeping the numbers seen in a set, O(n)).
Marking scheme
  • i. O(n²), because of the loop inside a loop over the list.
  • ii. About 20,000 seconds (about 5½ hours): 100 times the data, 10,000 times the work.
  • iii. A faster computer only divides the time by a fixed amount; the quadratic growth stays, so a better algorithm is needed.
3.
[3]

A cooperative in Ilam records the tea leaves its member gardens brought in one week, in kilograms:

gardens = [("Kanyam", 1200), ("Fikkal", 450), ("Soktim", 800), ("Mai Pokhari", 300)]

Write one line of Python for each, using lambda:

  • i.with filter, a list of the gardens that brought 500 kg or more;
  • ii.with map, a list of the names of those gardens;
  • iii.with reduce, the total kilograms brought by all four gardens.
Answer
from functools import reduce gardens = [("Kanyam", 1200), ("Fikkal", 450), ("Soktim", 800), ("Mai Pokhari", 300)]big = list(filter(lambda g: g[1] >= 500, gardens))names = list(map(lambda g: g[0], big))total = reduce(lambda a, b: a + b, [kg for name, kg in gardens])print(big)print(names)print(total)

Output

[('Kanyam', 1200), ('Soktim', 800)]['Kanyam', 'Soktim']2750

(reduce(lambda total, g: total + g[1], gardens, 0) is also right.)

Marking scheme
  • i. list(filter(lambda g: g[1] >= 500, gardens)).
  • ii. list(map(lambda g: g[0], …)) on the filtered list.
  • iii. reduce with a lambda that adds, over the kilograms (2,750), with reduce imported from functools.
4.
[3]

A savings cooperative with five branches in Syangja is moving its members’ accounts from paper ledgers to a new program.

  • i.Which way of changing over would you recommend? Give a reason.
  • ii.Why would a direct changeover be risky here?
  • iii.Write one drawback of the way you chose.
Answer

One good answer: i. A pilot changeover: one branch uses the new program first (keeping its ledgers alongside for the first weeks), then the others, so problems hurt one branch only, and its staff then help train the rest. (Parallel running in every branch is also a good choice: every balance is checked against the ledger, and any difference shows a mistake.)

  • ii.With a direct changeover the ledgers stop the day the program starts: if the program has a bug or the balances were entered wrongly, members’ money is wrong and there is nothing to fall back on or compare with.
  • iii.Pilot: the other four branches wait longer for the new program, and for a while the branches work in two different ways. (Parallel: every transaction is entered twice, which is double work for busy staff.)
Marking scheme
  • i. A suitable way (pilot, parallel or phased) with a reason that fits members’ money.
  • ii. Direct leaves nothing to fall back on or compare with if the program or the data is wrong.
  • iii. A real drawback of the way chosen (double work, waiting branches, two systems at once).
5.
[3]

Sunita’s savings account holds Rs 10,000. At the same moment, counter 1 records a deposit of Rs 2,000 for her and counter 2 a deposit of Rs 500. Each counter’s program reads the balance, adds the deposit, and writes the new balance. Both read 10,000; counter 1 writes 12,000, then counter 2 writes 10,500.

  • i.What should the balance be, and what is it?
  • ii.What is this problem called, and why did it happen?
  • iii.How does record locking prevent it?
Answer
  • i.It should be 10,000 + 2,000 + 500 = Rs 12,500; it is Rs 10,500: the Rs 2,000 deposit has vanished.
  • ii.A lost update: both transactions read the same balance before either wrote, and each wrote its own result, so the later write overwrote the earlier one.
  • iii.The first counter locks the record before reading it; the second must wait until the first commits and lets the lock go. Then it reads 12,000 and writes 12,500.
Marking scheme
  • i. Should be Rs 12,500; is Rs 10,500.
  • ii. A lost update, because both read before either wrote, and the second write overwrote the first.
  • iii. A lock makes the second counter wait until the first commits, so it reads the new balance.
6.
[3]

A news website asks its readers, “Should the school day start at 10 o’clock?”, and 8,000 readers answer: 70% say yes.

  • i.Why can’t this show what Nepal’s parents think?
  • ii.Would 80,000 answers in the same way fix the problem? Give a reason.
  • iii.A random sample of 400 parents gives an answer that is usually within about 5 percentage points of the truth. How many parents would make it about 2.5 points?
Answer
  • i.The sample is self-selected: only people who read that website and chose to answer, often those who feel strongly, so it is biased. Parents without the internet, or who don’t read that site, are left out.
  • ii.No. A bigger sample shrinks the chance error, but bias misses in one direction, and more of the same kind of answers misses in the same direction.
  • iii.The sampling error shrinks like 1 ÷ √(sample size), so halving it needs four times the sample: 1,600 parents.
Marking scheme
  • i. Self-selected readers of one website: biased, not a random sample of parents.
  • ii. No: a bigger sample reduces chance error, not bias.
  • iii. 1,600 (four times the sample halves the error).
7.
[3]

A ride app tried 20 new colors for its “Book” button, each in its own A/B test against the old button. Orange got 3% more bookings, with p = 0.04, and none of the others was significant. The team says, “Orange works,” and changes the button for everyone. Judge their conclusion, and say what they should have done.

Answer

The conclusion is not safe. At the 5% level, a difference this big turns up by chance about 1 time in 20 when there is nothing there; with 20 colors tested, about one is expected to look “significant” even if no color makes any difference. Picking the one that “worked” out of many is p-hacking. Besides, p = 0.04 isn’t the chance that orange works, and says nothing about whether 3% matters.
They should test orange again in a new A/B test, with the measure and the size of the test decided in advance (preregistered), and report all 20 tests, not just the one (or use a stricter limit for so many tests).

Marking scheme
  • With 20 tests, about one is expected to pass at 5% by chance, so orange may be a chance result.
  • Reporting only the one that worked out of many is p-hacking (a p-value isn’t the chance it works, and says nothing of size).
  • A fair next step: test orange again in a new, preregistered test, and report every test (or use a stricter limit).
8.
[3]

Anisha makes a tiny RSA key pair with p = 5 and q = 11, and the public power e = 3.

  • i.Work out n and φ(n).
  • ii.Show that d = 27 is a correct private power.
  • iii.Bikash encrypts the message m = 8 with her public key. Work out the ciphertext.
Answer
  • i.n = 5 × 11 = 55; φ(n) = (5 − 1)(11 − 1) = 4 × 10 = 40.
  • ii.e × d = 3 × 27 = 81 = 2 × 40 + 1, one more than a multiple of φ(n), so d = 27 undoes e = 3.
  • iii.c = 8³ mod 55 = 512 mod 55. 9 × 55 = 495, and 512 − 495 = 17, so c = 17. (Decrypting, 17²⁷ mod 55 gives 8 again.)
Marking scheme
  • i. n = 55 and φ(n) = 40.
  • ii. 3 × 27 = 81 = 2 × 40 + 1.
  • iii. c = 512 mod 55 = 17.
9.
[3]

Arguments about “thinking machines” often mix up three different questions. Name the three, and say what each asks.

Answer
  • Intelligence: what can the system do: solve problems, learn, plan, use language? It can be tested by giving it tasks.
  • Consciousness: does it experience anything, such as pain or joy? No agreed test exists.
  • Responsibility: who answers for what it does, and can it be wronged? This is decided by people, in ethics and law.
Marking scheme
  • Intelligence: what it can do (testable with tasks).
  • Consciousness: whether it experiences or feels anything.
  • Responsibility: who answers for what it does.

Section C

2 × 8 = 16

Write long answers to the following questions.

10.
[8]

A. A courier in Pokhara delivers from its office at Lakeside. These are the riding times, in minutes, along the roads between its stops on a quiet morning (made-up times). Every road goes both ways.

Road Minutes
Lakeside – Birauta 8
Lakeside – Srijana Chowk 10
Birauta – Prithvi Chowk 12
Srijana Chowk – Prithvi Chowk 6
Srijana Chowk – Mahendrapul 9
Prithvi Chowk – Mahendrapul 5
Prithvi Chowk – Bagar 15
Mahendrapul – Bagar 7
Mahendrapul – Lamachaur 20
Bagar – Lamachaur 10
  • i.Use Dijkstra’s algorithm to find the quickest route from Lakeside to Lamachaur. Write a row for each visit: the stop visited, its time, what changes, and the stops waiting, nearest first. (3)
  • ii.Write the quickest time and the route. (1)

B. At the school’s science fair, the game stalls take coupons of 1, 4 and 5 points. A prize costs 8 points.

  • iii.How many coupons does the greedy method give for 8 points? (1)
  • iv.Fill a table of the fewest coupons for every amount from 0 to 8, by dynamic programming, with the last coupon for each. (2)
  • v.Read the fewest coupons for 8 points from your table. (1)
Answer

i.

Visit Its time Roads checked: what changes Waiting, nearest first
Lakeside 0 Birauta 8, Srijana Chowk 10: new Birauta 8, Srijana Chowk 10
Birauta 8 Prithvi Chowk 8 + 12 = 20: new Srijana Chowk 10, Prithvi Chowk 20
Srijana Chowk 10 Prithvi Chowk 10 + 6 = 16: shorter than 20, now from Srijana Chowk. Mahendrapul 19: new Prithvi Chowk 16, Mahendrapul 19
Prithvi Chowk 16 Mahendrapul 21: not shorter than 19. Bagar 31: new Mahendrapul 19, Bagar 31
Mahendrapul 19 Bagar 19 + 7 = 26: shorter than 31, now from Mahendrapul. Lamachaur 39: new Bagar 26, Lamachaur 39
Bagar 26 Lamachaur 26 + 10 = 36: shorter than 39, now from Bagar Lamachaur 36
Lamachaur 36 the goal: stop

ii. 36 minutes. Following the notes back: Lamachaur came from Bagar, Bagar from Mahendrapul, Mahendrapul from Srijana Chowk, Srijana Chowk from Lakeside: Lakeside → Srijana Chowk → Mahendrapul → Bagar → Lamachaur. (The road straight from Mahendrapul to Lamachaur looked shorter, 39 minutes, but going round by Bagar is 3 minutes quicker.)

iii. Greedy takes the biggest that fits, 5, leaving 3, then 1, 1, 1: 4 coupons (5 + 1 + 1 + 1).

iv. For each amount, try each coupon that fits: that coupon, plus the best for what is left.

Amount Try 1 Try 4 Try 5 best last coupon
0 0
1 1 + best[0] = 1 1 1
2 1 + best[1] = 2 2 1
3 1 + best[2] = 3 3 1
4 1 + best[3] = 4 1 + best[0] = 1 1 4
5 1 + best[4] = 2 1 + best[1] = 2 1 + best[0] = 1 1 5
6 1 + best[5] = 2 1 + best[2] = 3 1 + best[1] = 2 2 1 (or 5)
7 1 + best[6] = 3 1 + best[3] = 4 1 + best[2] = 3 3 1 (or 5)
8 1 + best[7] = 4 1 + best[4] = 2 1 + best[3] = 4 2 4

v. For 8 the last coupon is a 4, leaving 4, whose last coupon is a 4, leaving 0: 2 coupons, 4 + 4, half as many as greedy.

Marking scheme
  • i. The visits in the right order: Lakeside, Birauta, Srijana Chowk, Prithvi Chowk, Mahendrapul, Bagar, Lamachaur.
  • i. Prithvi Chowk relaxed from 20 to 16 when Srijana Chowk is visited, and Mahendrapul not changed (21 is not shorter than 19).
  • i. Bagar relaxed from 31 to 26 and Lamachaur from 39 to 36.
  • ii. 36 minutes, by Lakeside → Srijana Chowk → Mahendrapul → Bagar → Lamachaur, read back from the came-from notes.
  • iii. 4 coupons (5 + 1 + 1 + 1).
  • iv. Each amount worked out from each coupon that fits, plus the best for what is left.
  • iv. The fewest coupons correct from 0 to 8 (0, 1, 2, 3, 1, 1, 2, 3, 2), with a last coupon for each.
  • v. 2 coupons, 4 + 4, read back through the last coupons.
11.
[8]

A municipality in Karnali wants to use a model that flags Grade 8 students who are likely to drop out of school, so that a teacher can visit each flagged family with support (a scholarship, books, a uniform). The builders tested it on 400 students from earlier years, 40 of whom did drop out.

Flagged Not flagged
Dropped out 24 16
Stayed 36 324

Split by where the students live:

Dropped out, flagged Dropped out, not flagged Stayed, flagged Stayed, not flagged
Bazaar wards (250 students) 12 3 18 217
Remote wards (150 students) 12 13 18 107
  • i.Work out the model’s accuracy, precision and recall over all 400 students. (3)
  • ii.Work out its recall in the bazaar wards and in the remote wards. What does the difference mean? (2)
  • iii.Should the municipality use the model? Argue your case, and say what must be done first, or how it must be used. (3)
Answer

i. TP = 24, FN = 16, FP = 36, TN = 324.

  • Accuracy = (24 + 324) ÷ 400 = 348 ÷ 400 = 87%
  • Precision = 24 ÷ (24 + 36) = 24 ÷ 60 = 40%: 2 in 5 flagged students really dropped out.
  • Recall = 24 ÷ (24 + 16) = 24 ÷ 40 = 60%: it catches 3 in 5 of those who drop out.

ii. Bazaar wards: 12 ÷ (12 + 3) = 80%. Remote wards: 12 ÷ (12 + 13) = 48%. In the remote wards, where 25 of the 40 dropouts were, it misses more than half of the students who leave: those most in need are the ones it helps least. The overall 60%, and still more the 87% accuracy, hid this gap. The likely cause is the data: fewer, or poorer, records from the remote wards.

iii. One well-argued case (other conclusions earn marks with good reasons): Use it only after the gap is closed, and only to offer help.

  • The cost of each mistake. A false alarm costs a teacher’s visit and some support to a family that may not need it: little harm, as long as being flagged never brings shame or a penalty. A miss costs a child’s schooling. So recall matters more than precision here, and 40% precision is acceptable.
  • The gap first. As it is, the model would send most visits to the bazaar wards and leave out the remote wards’ children, making an existing inequity worse. Collect better data from the remote wards and retrain it, then measure each group again. A lower threshold for the remote wards could be a short-term step, since a false alarm costs little here, but it only moves the line on scores that are already poor, so it brings many more false alarms; it doesn’t fix the cause.
  • How to use it. Teachers decide who is visited, using the flag as one piece of information with what they know (human review); families are told why they are visited, and no one is ever refused support because the model did not flag them; the results are checked each year by ward (drift), with a model card saying what it was tested on, and a way to stop using it.
  • (A simpler rule, such as many days absent, could be compared first: if it does as well, it is easier to explain.)
Marking scheme
  • i. Accuracy 87%.
  • i. Precision 40%.
  • i. Recall 60%.
  • ii. Recall 80% in the bazaar wards and 48% in the remote wards.
  • ii. It misses more than half the remote dropouts, where the need is greatest; the overall figures hid the gap.
  • iii. A clear conclusion argued from the cost of each kind of mistake (a missed dropout costs more than a visit, so recall matters most).
  • iii. The gap dealt with at its cause: better data from the remote wards and retraining (a lower threshold for them only as a short-term step, with its extra false alarms).
  • iii. Safeguards for its use: teachers decide (human review), families told, never used to refuse support, results checked by group after release.

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]

Stamps. The school’s model post office sells stamps of Rs 1, 7, 10 and 15 (made-up values). Write a function fewest_stamps(amount) that returns a list of the fewest stamps that make the amount exactly, and automatic tests for it, run by a small test runner, with at least one test where taking the biggest stamp first would give more stamps. Show the tests passing, then print the stamps for Rs 21 and Rs 49.

STAMPS = [1, 7, 10, 15] def fewest_stamps(amount):    return [] # Your tests here
Answer
STAMPS = [1, 7, 10, 15]  def fewest_stamps(amount):    """The fewest stamps that make amount exactly, as a list."""    best = [0] + [None] * amount     # best[a]: fewest stamps for a    last = [None] * (amount + 1)     # last[a]: the stamp that does it    for a in range(1, amount + 1):        for stamp in STAMPS:            if stamp <= a and best[a - stamp] is not None:                if best[a] is None or best[a - stamp] + 1 < best[a]:                    best[a] = best[a - stamp] + 1                    last[a] = stamp    given = []    a = amount    while a > 0:        given.append(last[a])        a = a - last[a]    return sorted(given, reverse=True)  def test_nothing():    assert fewest_stamps(0) == []  def test_one_stamp():    assert fewest_stamps(15) == [15]    assert fewest_stamps(1) == [1]  def test_greedy_would_fail():    # greedy gives 10 + 1 + 1 + 1 + 1 for 14: five stamps    assert fewest_stamps(14) == [7, 7], f"14 gave {fewest_stamps(14)}"  def test_sum_is_right():    for amount in range(0, 101):        assert sum(fewest_stamps(amount)) == amount, f"{amount} gave the wrong sum"  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")print("Rs 21:", fewest_stamps(21))print("Rs 49:", fewest_stamps(49))

Output

PASS test_nothingPASS test_one_stampPASS test_greedy_would_failPASS test_sum_is_right4 passed, 0 failedRs 21: [10, 10, 1]Rs 49: [15, 10, 10, 7, 7]

Rs 21 is 3 stamps (7 + 7 + 7 is also 3, and right); greedy would give 15 and six 1s, seven stamps. Rs 49 is 5 stamps.

Marking scheme
  • A table of the fewest stamps for every amount from 0 up, each from smaller amounts (dynamic programming), not greedy.
  • Keeps the last stamp for each amount and reads the stamps back from it.
  • Returns a list of stamps (not prints), and [] for 0.
  • Tests written as test_ functions with assert, with answers worked out by hand.
  • A test where greedy would fail (such as 14 = 7 + 7, or 21).
  • A runner that runs every test and reports passes and failures; all pass.
  • Prints 3 stamps for Rs 21 and 5 stamps for Rs 49.
P2.
[4]

The failing test. A savings cooperative’s requirement says: “Savings of Rs 50,000 or more earn 8% a year; less than that earns 6%. Interest is rounded to the nearest rupee.” Run the tests, find why one fails, fix it, and run them again.

def yearly_interest(balance):    """A year's interest in rupees on a savings balance."""    if balance > 50000:        rate = 8    else:        rate = 6    return round(balance * rate / 100)  def test_normal():    assert yearly_interest(20000) == 1200    assert yearly_interest(120000) == 9600  def test_boundary():    assert yearly_interest(50000) == 4000, f"50000 gave {yearly_interest(50000)}"    assert yearly_interest(49999) == 3000  def test_zero():    assert yearly_interest(0) == 0  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_normalFAIL test_boundary 50000 gave 3000PASS test_zero2 passed, 1 failed

The boundary test fails: Rs 50,000 earns 6% (Rs 3,000) instead of 8% (Rs 4,000). The requirement says “Rs 50,000 or more”, so the test is right and the code is wrong: line 3 uses >, which leaves out 50,000 itself. Change it to >=:

def yearly_interest(balance):    """A year's interest in rupees on a savings balance."""    if balance >= 50000:        rate = 8    else:        rate = 6    return round(balance * rate / 100)  def test_normal():    assert yearly_interest(20000) == 1200    assert yearly_interest(120000) == 9600  def test_boundary():    assert yearly_interest(50000) == 4000, f"50000 gave {yearly_interest(50000)}"    assert yearly_interest(49999) == 3000  def test_zero():    assert yearly_interest(0) == 0  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_normalPASS test_boundaryPASS test_zero3 passed, 0 failed
Marking scheme
  • Runs the tests and names the failing one: the boundary test, 50,000 gives 3,000.
  • Finds the cause: > on line 3, which leaves out exactly Rs 50,000.
  • Fixes the code with >= (not the test), because the requirement says “or more”.
  • Runs all the tests again, and all pass.
P3.
[4]

The tiger camera. A model looks at photos from camera traps in Chitwan National Park and says whether each shows a tiger. It was tested on 60 photos checked by a ranger. In the strings below, each position is one photo: truth has T where there really is a tiger, said has T where the model said tiger, and light says whether the photo was taken by day (D) or at night (N). (The photos and results are made up.)

Write a program that counts the four outcomes and works out the model’s precision and recall, for all 60 photos and for the day and the night photos apart. Then write one limit of the model, in a sentence for the park, with the numbers that show it.

truth = "--T-----T--TT----------------T-----T--------TT-----T--TT--T-"said  = "T-------T---T----------------T----TT----T---TTT----T--TT----"light = "DNNNNNDDDDDNNDNNDNDNDDDNNNNNDDNDNDNNNNDNNNDDDDDDNDDNDNDDNDND" # Your program here
Answer
truth = "--T-----T--TT----------------T-----T--------TT-----T--TT--T-"said  = "T-------T---T----------------T----TT----T---TTT----T--TT----"light = "DNNNNNDDDDDNNDNNDNDNDDDNNNNNDDNDNDNNNNDNNNDDDDDDNDDNDNDDNDND"  def measure(name, when):    """Count the outcomes for the photos taken in `when` (D, N or both)."""    tp = fp = fn = tn = 0    for real, model, l in zip(truth, said, light):        if l not in when:            continue        if real == "T" and model == "T":            tp += 1        elif real == "T":            fn += 1        elif model == "T":            fp += 1        else:            tn += 1    precision = tp / (tp + fp)    recall = tp / (tp + fn)    print(f"{name:6} TP {tp:2}  FP {fp}  FN {fn}  TN {tn:2}  precision {precision:.0%}  recall {recall:.0%}")  measure("All", "DN")measure("Day", "D")measure("Night", "N")

Output

All    TP  9  FP 4  FN 3  TN 44  precision 69%  recall 75%Day    TP  6  FP 2  FN 0  TN 22  precision 75%  recall 100%Night  TP  3  FP 2  FN 3  TN 22  precision 60%  recall 50%

One limit: “By day the model found every tiger, but at night it missed half of them (3 of 6); and it was tested on only 12 tigers, too few to be sure of any of these numbers.” Tigers are often active at night, so night photos matter; the model needs more night photos to learn from and to be tested on.

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: 69% and 75% for all photos.
  • The day and night photos measured apart (recall 100% by day, 50% at night).
  • One limit stated in a sentence with its numbers (the night recall, or only 12 tigers in the test).
P4.
[5]

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

  • i.In fewest_stamps, what does each place in your best list hold, and why can you trust it when you reach the next amount? (2)
  • ii.In the cooperative’s program, how did you decide that the code, not the test, was wrong? (1)
  • iii.The tiger model’s accuracy is 88%. Why is that not a good way to judge it? What would you do about the night photos? (2)
Answer
  • i.best[a] holds the fewest stamps for the amount a. Each amount is worked out from smaller amounts only (a − 1, a − 7, a − 10, a − 15), which are already in the list and already the best, so each answer is built from correct smaller answers, and each is worked out once.
  • ii.By reading the requirement: it says Rs 50,000 “or more” earns 8%, so the test’s 4,000 is right and the code’s > is wrong. A test is checked against the requirement, not against what the code happens to do.
  • iii.Tigers are rare in the photos (12 of 60): a model that said “no tiger” every time would still be 80% accurate. Accuracy is mostly about the common kind; precision and recall say how many tigers it finds and how far to trust its tiger photos. For the night photos: collect and label many more night photos, retrain, and test again by day and night apart.
Marking scheme
  • i. best[a] is the fewest stamps for amount a.
  • i. Each is built from smaller amounts already worked out, so it can be trusted.
  • ii. From the requirement (“or more”): the test matches it and the code doesn’t.
  • iii. Tigers are rare, so a model that never finds one would still look accurate.
  • iii. More (labeled) night photos to train and test on, measured by day and night apart.

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