Skip to main content

Trace and Repair

Before the lab, write the states for a loop totaling [12, 8, 12]. Predict what happens if the initial total moves inside the loop, if return moves inside the loop, and if the list becomes a set. Run each altered version and explain the discrepancy.

Next create three failures: use an undefined variable, convert "ten" with int, and access the first item of an empty list. For each, identify the exception type and the line responsible. Restore your working file afterward.

Finally write count_at_least([12, 8, 12], 12) and tests for empty input and equality. Expected result is 2; equality qualifies. Save your own state trace before consulting the answer key.