CHECKPOINT 1  -  SET B
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_setB_key.txt:
open it only after you finish.

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

QUESTION 1   [Mechanism]

Maya spends twenty minutes in one chat telling a model her team's project code names. Later in the same chat, the model uses them correctly. She says, "It learned our code names." The next morning, in a new chat, the model gets them wrong.

(a) What actually happened during the first chat? Use the words weights, training and context correctly.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(b) Explain the next-morning result.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

QUESTION 2   [Mechanism]

Someone asks a model which clause of the national building standard sets the minimum width of a fire exit door. The model answers with a document title, a clause number and a quoted sentence, all in a confident tone. None of them exist.

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

(b) Explain mechanically how it can produce a fluent, specific citation that does not exist.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(c) The person says, "It sounded so certain." What does the confident tone tell you about whether the answer is correct, and 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) "How many days are in a leap year?"
    ______________________________________________________________
    ______________________________________________________________

(b) "Using the race times I typed into this chat earlier, who had the fastest run?"
    ______________________________________________________________
    ______________________________________________________________

(c) "What does the spreadsheet on my laptop's desktop say about next week's shift rota?" (The file has not been pasted or uploaded.)
    ______________________________________________________________
    ______________________________________________________________

(d) "What changes did my manager announce at this morning's team meeting?"
    ______________________________________________________________
    ______________________________________________________________

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

QUESTION 4   [Code reading and tracing]

Read this program. Do not run anything.

L18_B_q4.py (line numbers added for reference):
 1  tail = "VAN-"
 2  number = 2
 3  print(tail + str(number))
 4  print(number * 2.5)
 5  print("7" + "1", 7 + 1)

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

QUESTION 5   [Code reading and tracing]

L18_B_q5.py (line numbers added for reference):
 1  temp = 95
 2  wind = 18
 3  if wind > 25:
 4      decision = "CANCEL"
 5  elif temp > 90:
 6      decision = "MODIFY"
 7  else:
 8      decision = "PROCEED"
 9  print(decision)
10  print(wind - 25)

(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_B_q6.py (line numbers added for reference):
 1  miles = 0
 2  for leg in range(2, 6):
 3      miles = miles + leg * 3
 4      print(leg, miles)
 5  print("total", miles)

(a) Complete a trace table with one row for each pass through the loop. Columns: leg, and miles 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_B_q7.py (line numbers added for reference):
 1  fuel = 100
 2  legs = 0
 3  while fuel > 30:
 4      fuel = fuel - 25
 5      legs = legs + 1
 6  print(legs, fuel)

(a) State in words when this loop stops, and say whether fuel can end below 30.
    ______________________________________________________________
    ______________________________________________________________

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

QUESTION 8   [Code reading and tracing]

L18_B_q8.py (line numbers added for reference):
 1  def count_at_least(values, minimum):
 2      count = 0
 3      for v in values:
 4          if v >= minimum:
 5              count = count + 1
 6      return count
 7
 8
 9  scores = [78, 90, 75, 62, 75]
10  print(count_at_least(scores, 75))
11  print(count_at_least(scores, 91))

(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_B_q9_broken.py (line numbers added for reference):
 1  def total_sold(lines):
 2      total = 0
 3      for line in lines:
 4          total = total + int(line)
 5      return total
 6
 7
 8  log = ["4", "3", "", "5"]
 9  print(total_sold(log))

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_B_q9_broken.py", line 9, in <module>
    print(total_sold(log))
          ~~~~~~~~~~^^^^^
  File "L18_B_q9_broken.py", line 4, in total_sold
    total = total + int(line)
                    ~~~^^^^^^
ValueError: invalid literal for int() with base 10: ''

(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_B_q10.py (line numbers added for reference):
 1  # A ticket desk has 40 tickets and sells them in batches of 10.
 2  # Print the tickets left after each batch and stop when none are left.
 3  tickets = 40
 4  batches = 0
 5  while tickets >= 0:
 6      tickets = tickets - 10
 7      batches = batches + 1
 8      print("Batch", batches, "sold. Tickets left:", tickets)
 9  print("Sold out after", batches, "batches")

(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: change line 5 to while tickets > 10:. 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]

The events team says: "Make me something that warns us when the weather is too bad for the outdoor market." Each hour a reading arrives with wind speed in miles per hour, rainfall in millimetres, and temperature in degrees Celsius.

(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]

Your specification says: "A meeting that runs 30 minutes or more is over the limit." You ask a model for the function. 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-4 of L18_B_q12.py: the function only:
 1  def over_limit(minutes):
 2      if minutes > 30:
 3          return True
 4      return False

"This function does exactly what your specification asks. For example, over_limit(31) returns True and over_limit(29) returns False, so the boundary is handled correctly."

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) What tests would settle whether the function meets the specification? Give each input and the result the specification requires, and say what the authority is for the expected result and for the actual result.
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________
    ______________________________________________________________

(c) Without running anything, predict what over_limit(30) returns. Does that meet the specification?
    ______________________________________________________________
    ______________________________________________________________
