Answer Key and Calibration
Exercise calibration
- Text yields
"128"; integer addition yields 20. - Running totals: 12, 20, 32. An empty list leaves the initial zero unchanged.
- Increase a counter for every value greater than or equal to the target. A good contract specifies validated integer inputs and leaves the list unchanged.
- A set removes duplicates; equal durations can be different sessions.
- The endpoints are accepted; immediately outside them is rejected.
- Save the original bytes, call the loader on invalid data, expect an error, and compare the file bytes afterward.
- For example, whitespace around each field checks normalization; a failed save checks that the CLI reports an error rather than claiming success. Explain why your case is distinct.
Reasoning calibration
Assignment binds a value; comparison returns a Boolean. Print produces output; return supplies a value to the caller. Missing storage has a defined first-run interpretation. Corruption does not. JSON booleans are a different domain value from whole study minutes, even though Python permits some integer operations on them. Tests sample behavior and may omit cases or share the implementation's mistaken assumptions.
Transfer calibration
For pages [12, 8, 12] and target 12, expect count 3, total 32, longest 12 and qualifying count 2. Empty history gives four zeros. Values 1 and 500 are valid; 0 and 501 are invalid. A correct implementation must also preserve the existing file after rejection and explain its storage limitations.
The lab's reference.py is a calibration implementation, not a unique required design. Different decompositions are acceptable if they satisfy the contracts and are understandable.
Design and diagnosis calibration
Read only after preserving your attempt. For first_over_budget([4,6],10), return None; [4,7] gives 1; [11] gives 0; [] gives None; [0,0] at budget 0 gives None; [0,1] at budget 0 gives 1. Keep duplicates: [4,4,4] at budget 8 rejects index 2. The running total equals the sum of the processed prefix. Because all costs are nonnegative, the first strict exceedance is the requested event; checking equality as overflow is incorrect.
For the changed requirement, one acceptable contract returns (index, remaining_before_rejection) or (None, final_remaining) if all costs fit. [4,7] at 10 gives (1,6); [4,6] at 10 gives (None,0). Other explicit, coherent representations are acceptable. A diagnosis that merely says “replace >= with >” is incomplete without predicted evidence and a regression case. An always-return-last-index hypothesis is contradicted by [11,0] at 10, which the supplied candidate rejects at index 0; an equality experiment separately tests the boundary hypothesis.
For the earliest-longest-run drill, preserve the earliest start on ties: update the best start only when a strictly longer run is found. Return None when no run qualifies, not index 0. [10,25,25,10,25,25] at 25 gives 1.
Retention calibration
Seven-day task: [4,6] at capacity 10 accepts 2; [4,7,0] accepts 1; [11,0] accepts 0; an empty list accepts 0; [0,0] at 0 accepts 2. Do not continue past a rejected package. Correct results with no explanation of the return convention require repair.
Four-week task: readings [2,3,8,2,3] in inclusive interval [2,3] have longest run 2; [2,3,3] gives 3; [1,4] gives 0; empty input gives 0. The two counters retain their meanings; the predicate becomes low <= reading <= high. These are calibration examples, not the learner's full test suite or evidence that a pilot occurred.
Optional practice calibration
A. The first line displays 20 25; saved keeps the earlier integer. The next lines display 2020 and 40: string repetition differs from multiplication of integers. At 59, 60 and 61 minutes, complete hours/remainder pairs are (0, 59), (1, 0) and (1, 1). Integer conversion does not enforce positivity or a maximum duration.
B. 0 and 241 are outside the range; 1 and 24 are short; 25 and 240 are focused. Totals are 5, 15, 20. Resetting inside the loop leaves only the latest duration, giving 5. The countdown from 1 prints 1 then Done; from 0 it prints only Done.
C. One implementation, trusting the stated nonnegative-integer precondition:
def minutes_above_target(minutes, target):
if minutes <= target:
return 0
return minutes - target
assert minutes_above_target(10, 20) == 0
assert minutes_above_target(20, 20) == 0
assert minutes_above_target(25, 20) == 5
assert minutes_above_target(0, 0) == 0
extra = minutes_above_target(25, 20)
print(f"Extra study minutes: {extra}")
A negative answer violates the contract. Printing inside the function does not supply its result to the caller. Checking only (25, 20) misses both of those boundary cases.
D. With assignment, both names show [10, 20, 30]. With a fresh list and a copy, history stays [10, 20] while draft becomes [10, 20, 30]. The copy supports this independent experiment because these elements are integers; it is not a general deep-copy guarantee.
E. broken fails JSON parsing; {} has the wrong outer shape; [true] and ["25"] have the wrong element types; [0] is out of range; [240] and [] are accepted. An explicit valid empty list is data. Treating corruption as an empty list invents replacement data and may overwrite history.
F. Returning from inside the first loop iteration and overwriting the total on every iteration both give 5 for the original input. [2, 9] distinguishes them: the early return predicts 2; overwriting predicts 9; the correct total is 11. Inspect return indentation for the first observation and the accumulator update for the second. Other hypotheses are acceptable if the experiment actually distinguishes their predictions.