PY-42

Record an Expected Failure

  • Easy–Medium
  • Expected Failures
  • Python

Task

Write convert_reading(record_id, text). It tries to convert text with float(text) and returns one stable dictionary record.

When conversion succeeds, return exactly:

When float(text) raises ValueError, catch that exception and return:

Catch only ValueError. A different failure, such as the TypeError produced by float(None), is outside this function's recovery rule and must remain visible to its caller. Keep only the conversion operation inside the try block.

Example

The fixed reason makes failure records comparable even when the rejected text differs. It does not claim that the invalid text was repaired.

Your implementation

Edit solution.py and keep this function name and signature:

Return a new dictionary with exactly the four stated keys. Do not print, ask for input, or catch a broader exception.