Skip to main content

Prerequisite Diagnostic

Allow 30–45 minutes; first answer without the feedback.

  1. What happens to a when a=[1]; b=a; b.append(2) runs? What changes if b is a copy?
  2. Trace an object starting at 3 whose add(x) adds x, followed by add(2), then a read.
  3. A function appends to a list and then raises. Does catching the exception undo the append?
  4. What does a second loop observe after a generator is fully consumed?
  5. Explain the difference between a test passing on one input and a universal contract.

Feedback and repair​

  1. a becomes [1,2]; copying the outer list prevents that structural alias.
  2. The observed value is 5; distinguish separate instances from shared references.
  3. No. Exceptions transfer control; they do not automatically roll back mutation.
  4. No remaining elements. A list is reusable; an exhausted iterator is not.
  5. The test is bounded evidence. General reasoning needs explicit assumptions.

Repair tracing/functions in Semester 0, contracts/proof discipline in Semester 1, and iterator or stateful testing gaps through a small hand trace. Do not require pre-existing SOLID expertise or advanced inheritance knowledge to enter this module.