PY-40

Find and Repair a Wrong Result

  • Easy–Medium
  • Wrong-Result Debugging
  • Python

Task

The supplied summarize_available(readings) function runs, but it gives a wrong result when readings contains None. A None value means that no reading is available at that position. It must affect neither the total nor the count.

Repair the function so it returns a dictionary with exactly these keys:

  • total: the sum of the available readings;
  • count: the number of available readings;
  • mean: total / count, or None when no reading is available.

Do not change readings. Keep check_original_failure() as a regression check: it must call summarize_available([18.0, None, 24.0]) and assert the complete expected dictionary. The check returns nothing when it passes.

Example

The starting function increases count before it skips None:

For [18.0, None, 24.0], the total is correctly 42.0, but the faulty count is 3, so the mean becomes 14.0. The first wrong intermediate value is the count immediately after the None item.

Your implementation

Edit solution.py. Keep both function names and signatures:

Return a new dictionary from summarize_available. Preserve the numeric result produced by Python: an integer-only input may have an integer total, while a non-empty mean uses division. Do not print or ask for input.