CHECKPOINT 1  -  SET A
Closed book. No AI, no notes, no network, no calculator, no running code.
Time: about 45 minutes. Answer on paper or in a blank text file.

All programs are Python. Line numbers at the left are for reference only;
they are not part of the program. The answer key is in L18_setA_key.txt:
open it only after you finish.

======================================================================
PART: MECHANISM
======================================================================

QUESTION 1   [Mechanism]

Priya uploads her company's 30-page employee handbook into a chat with a model and asks it questions all evening. The answers are good. She tells a colleague: "The model has been trained on our handbook now. Tomorrow you can open your own chat and ask it about our handbook."

(a) What actually happened when Priya uploaded the handbook and asked her questions? Use the words weights, training and context correctly.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(b) What will the colleague get tomorrow in a new chat, and why?
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

QUESTION 2   [Mechanism]

Two colleagues type the identical prompt, "Write a two-sentence safety reminder for the warehouse night shift," into the same model a minute apart. They get different wording. Lee says the model must be broken. Park says the model changed its mind.

(a) Describe what the model computes, step by step, while it produces an answer.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(b) Explain mechanically why the two answers differ. Address both explanations.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(c) What would you expect if the temperature setting were lowered? Would that make the answer more likely to be correct? Why?
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

QUESTION 3   [Mechanism]

The three circles from L7 are: training data, context, and inaccessible. Assume a general-purpose model with no web search, no file access and no other tools, used in a new chat unless the question says otherwise. For each question below, name the circle the needed information sits in, and give a one-line reason.

(a) "What is the chemical symbol for sodium?"
    ______________________________________________________________
    ______________________________________________________________

(b) "In the delivery log I pasted two messages ago in this chat, which van has the most entries?"
    ______________________________________________________________
    ______________________________________________________________

(c) "What time does my team's stand-up start tomorrow? It was set by email this morning."
    ______________________________________________________________
    ______________________________________________________________

(d) "Who won the local league match last night?"
    ______________________________________________________________
    ______________________________________________________________

======================================================================
PART: CODE READING AND TRACING
======================================================================

QUESTION 4   [Code reading and tracing]

Read this program. Do not run anything.

L18_A_q4.py (line numbers added for reference):
 1  count = "12"
 2  extra = 3
 3  print(count + "3")
 4  print(int(count) + extra)
 5  print(int(count) / extra)

Write exactly what the program prints, one line per line of output.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

QUESTION 5   [Code reading and tracing]

L18_A_q5.py (line numbers added for reference):
 1  fuel = 2400
 2  reserve = 2500
 3  if fuel > reserve:
 4      status = "GO"
 5  elif fuel > reserve - 200:
 6      status = "CHECK"
 7  else:
 8      status = "NO GO"
 9  print(status)
10  print(fuel - reserve)

(a) Which branch runs: the if, the elif, or the else? Explain why, using the actual values.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(b) Write exactly what the program prints.
    ______________________________________________________________
    ______________________________________________________________

QUESTION 6   [Code reading and tracing]

L18_A_q6.py (line numbers added for reference):
 1  total = 0
 2  for day in range(1, 5):
 3      total = total + day * 2
 4      print(day, total)
 5  print("done", total)

(a) Complete a trace table with one row for each pass through the loop. Columns: day, and total after line 3 runs.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(b) Write exactly what the last line of output is.
    ______________________________________________________________

(c) How many times does the body of the loop run?
    ______________________________________________________________

QUESTION 7   [Code reading and tracing]

L18_A_q7.py (line numbers added for reference):
 1  hours = 10
 2  checks = 0
 3  while hours < 50:
 4      hours = hours + 15
 5      checks = checks + 1
 6  print(checks, hours)

(a) State in words when this loop stops, and say whether hours can end above 50.
    ______________________________________________________________
    ______________________________________________________________

(b) Write exactly what the program prints.
    ______________________________________________________________
    ______________________________________________________________

QUESTION 8   [Code reading and tracing]

L18_A_q8.py (line numbers added for reference):
 1  def count_over(values, limit):
 2      count = 0
 3      for v in values:
 4          if v > limit:
 5              count = count + 1
 6      return count
 7
 8
 9  deliveries = [3, 5, 2, 5, 7]
10  print(count_over(deliveries, 5))
11  print(count_over(deliveries, 1))

(a) Line 1 is the function's signature. What two inputs does the function take?
    ______________________________________________________________

(b) Read the body. In one sentence, what does the function return?
    ______________________________________________________________
    ______________________________________________________________

(c) Write exactly what the program prints.
    ______________________________________________________________
    ______________________________________________________________

======================================================================
PART: FAULT DIAGNOSIS
======================================================================

QUESTION 9   [Fault diagnosis]

This program stops with an error. The code and the full output are shown.

L18_A_q9_broken.py (line numbers added for reference):
 1  def average_hours(hours_list):
 2      total = 0
 3      for h in hours_list:
 4          total = total + h
 5      return total / len(hours_list)
 6
 7
 8  week = [6.5, 7, "8", 5.5]
 9  print(average_hours(week))

Output of the program above, captured on Python 3.13; the folder part of the path is removed:
Traceback (most recent call last):
  File "L18_A_q9_broken.py", line 9, in <module>
    print(average_hours(week))
          ~~~~~~~~~~~~~^^^^^^
  File "L18_A_q9_broken.py", line 4, in average_hours
    total = total + h
            ~~~~~~^~~
TypeError: unsupported operand type(s) for +: 'float' and 'str'

(a) Which line raised the error? Give the line number and the line.
    ______________________________________________________________
    ______________________________________________________________

(b) In plain words, what caused the error? Name the value responsible and where it came from.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(c) At the moment the error happened, what were the values of total and of the loop variable?
    ______________________________________________________________
    ______________________________________________________________

QUESTION 10   [Fault diagnosis]

This program runs without an error. The comment at the top says what it is supposed to do.

L18_A_q10.py (line numbers added for reference):
 1  # Six people are on the rota, numbered 1 to 6.
 2  # Send a reminder to each one and count how many were sent.
 3  staff = 6
 4  sent = 0
 5  for person in range(1, staff):
 6      print("Reminder sent to person", person)
 7      sent = sent + 1
 8  print("Sent", sent, "of", staff)

(a) Predict exactly what the program prints, one line per line of output.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(b) Does the program do what the comment says? If not, which line holds the fault, and what exactly is wrong with it?
    ______________________________________________________________
    ______________________________________________________________

(c) Write the corrected line, and write the last line the program would then print.
    ______________________________________________________________
    ______________________________________________________________

(d) A colleague proposes a different fix: leave line 5 alone and change line 8 to print("Sent", sent + 1, "of", staff). What would the program print, and is that a fix? This program never crashed, yet it was wrong: say why a silent wrong answer is worse than a crash.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

======================================================================
PART: METHOD
======================================================================

QUESTION 11   [Method]

Your manager says: "I need something that tells me which volunteers are behind on their hours this month." You have a text file with one line per shift: volunteer name, date, and hours worked.

(a) Decompose the request into at least three sub-problems. Each must be something one function could do, described in one sentence.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(b) List two assumptions or questions the request leaves open that must be settled before anyone writes code.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(c) Pick one of your sub-problems. Write its function signature and three acceptance criteria. Each criterion names a specific input and the expected result. At least one must test a boundary.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

======================================================================
PART: VERIFICATION REASONING
======================================================================

QUESTION 12   [Verification reasoning]

You ask a model for a function to average a list of numbers. Suppose it replies with the code and the message below. Both were written for this lesson; a real model's reply will differ.

Lines 1-5 of L18_A_q12_broken.py: the function only:
 1  def average(values):
 2      total = 0
 3      for v in values:
 4          total = total + v
 5      return total / len(values)

"Here is a function that returns the average of a list of numbers. I tested this function and it works for all inputs, including an empty list. For example, average([4, 6, 8]) returns 6.0."

Use the verification procedure from L6: identify the checkable claim, name the authority that would settle it, check it, record the result.

(a) List the checkable claims in the model's reply.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(b) For each claim, say what evidence would settle it and what the authority is.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(c) Without running anything, predict what happens when the function is given an empty list. Name the line responsible.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
