Pass Configuration and Return Results
Keep input data, chosen settings, and computed evidence separate by passing one configuration and returning one result record.
A measurement run needs three different kinds of information. The readings are the data being analyzed. The unit and thresholds are configuration. Counts and the mean are results produced by the analysis. Keeping these roles separate makes the function call and its evidence easier to inspect.
Declare Configuration and Result Records
The configuration contains settings chosen before the run:
The result contains evidence computed during the run:
The readings do not belong in either record. They remain the input data passed
to the analysis. Putting a particular dataset inside MeasurementConfig would
mix what the function should analyze with how it should interpret values.
The result includes unit because a returned mean without its unit is
ambiguous. It also includes the thresholds' resulting class counts rather than
silently changing global counters elsewhere.
Q1. Separate data, configuration, and result
Which assignment of roles is correct?
Select one choice, then check.
HintFollow when each value exists
Configuration is chosen before analysis. Results do not exist until analysis has inspected the data.
SolutionKeep the three roles explicit
Pass the readings as data and MeasurementConfig as settings. Return
MeasurementResult containing the computed evidence and its unit.
Pass the Configuration Explicitly
The analysis receives both dependencies in its signature:
No hidden global threshold decides the classification. A call shows which configuration applies:
The function first validates the relationship it requires:
frozen=True did not perform this validation. The analysis boundary knows that
the low threshold must be below the high threshold, so it rejects a
configuration that violates that rule.
Each None reading is unavailable. It increases rejected and does not enter
the mean or a numerical class. Every numerical reading is accepted and enters
exactly one class:
Q2. Predict the first configuration
For the fixed readings and MeasurementConfig(unit="°C", low=20.0, high=23.0),
which class counts should the result contain?
Select one choice, then check.
HintClassify only the five numbers
18.5 and 19.0 are low; 21.5 is ordinary; 24.0 and 23.5 are high.
SolutionThe classes contain two, one, and two readings
The result has low_count=2, ordinary_count=1, and high_count=2.
It also has accepted=5, rejected=1, and mean=21.3.
Return One Explicit Result
Here is the complete function:
Returning one record keeps the evidence together and names each part. The function does not mutate the readings or configuration.
Now change only the thresholds:
The accepted count, rejected count, mean, and unit remain the same. The class
counts become 1, 3, and 1. This comparison shows why the settings belong
in the call and the counts belong in the result.
| Configuration | Accepted | Rejected | Mean | Low / ordinary / high |
|---|---|---|---|---|
low 20, high 23 | 5 | 1 | 21.3 | 2 / 1 / 2 |
low 19, high 24 | 5 | 1 | 21.3 | 1 / 3 / 1 |
Q3. Return results for two configurations
Complete analyze so it validates threshold order, treats None as rejected,
and returns all seven result fields. Both configurations must preserve the mean
while producing different class counts.
Editable Python
Ready to run.
HintKeep one counter for each result field
Begin with threshold validation and zeroed counters. Skip None after
increasing rejected; otherwise update accepted, total, and exactly one
class. Return MeasurementResult with unit=config.unit.
SolutionPass settings in and return evidence
Keep data, configuration, and results in separate roles. Pass the frozen configuration explicitly, validate the relationship the computation needs, and return one named result record. Chapter 10 can replace the internal list with an array while preserving this visible configuration–computation–result boundary.