Checking your account

You can read the lesson while its saved answers and constructions load. Learning controls will open once that work is ready.

Python Design and Type Hints

Connect a New Thermometer to the Alert Counter

Coding challenges

BOTIE

Multiply each incoming reading by the supplied calibration multiplier, then add the offset. The first thermometer uses 1 and 0, leaving [10, 14, 18] unchanged. Keep these inputs as wires so a replacement can supply a different correction.
Ready to test
0 passed · 0 failed · 2 not run

An empty floor. Start with the information your machine needs.

Received result

Your answer will arrive here.

Examples, experiments and workspace controls
Live values

Connect a tool's inputs to see what it produces. You can try a branch before connecting it to Result.

Try your own inputs

Use a copy of the example to try your own data. Keep the problem's assumptions in mind, and predict the effect of a change before checking the output. You can also add another branch to compare two ways of doing the calculation.

Start at an output arrow, then click or drag to an input. Drag empty space to pan. Delete removes a selection. Ctrl/Cmd+Z undoes a change.
Context for this challenge

Multiply each incoming reading by the supplied calibration multiplier, then add the offset. The first thermometer uses 1 and 0, leaving [10, 14, 18] unchanged. Keep these inputs as wires so a replacement can supply a different correction.

The existing alert counter expects Celsius readings. A replacement thermometer needs a correction before its readings reach that counter. The supplied multiplier and offset describe that correction; the alert rule itself still uses the same Celsius limit.

Inspect the component calculation
Add(
  First contribution: Multiply(
    Value: Incoming thermometer readings
    Multiplier: Calibration multiplier
  )
  Second contribution: Calibration offset in Celsius
)
Examples and results
Incoming thermometer readings
  1. 010
  2. 114
  3. 218
Calibration multiplier
1
Calibration offset in Celsius
0
Required result
  1. 010
  2. 114
  3. 218
Incoming thermometer readings
  1. 02
Calibration multiplier
1
Calibration offset in Celsius
0
Required result
  1. 02
Try a fresh construction

This clears this draft, including its undo history. Earlier successful attempts stay recorded. Build again without opening hints to record an independent attempt.

Stuck? Inspect a worked construction

The tools below form one possible solution. You can assemble it, follow its signals, and undo that change to return to your own construction.

Assumptions and test precision

The correction is supplied for these invented thermometers; the workshop does not estimate a real calibration. It illustrates composing calculations. The Python examples introduce replaceable source and sink objects. Numerical tests allow a difference of 0.001. Lists and structures must also have the right shape.

Your last tested pieces can start the full construction. An existing draft there keeps its own pieces.

The Correction Reverses the Reading Order

This check uses the pieces from “Connect the Corrected Readings to the Counter”.

BOTIE

A different thermometer supplies [-3, 4], with a multiplier of -2 and an offset of 10. The alert limit is still expressed in corrected Celsius, at 10 degrees.
Incoming thermometer readings
  1. 0-3
  2. 14
Calibration multiplier
-2
Calibration offset in Celsius
10
Alert limit in corrected Celsius
10

Saving your prediction runs your current construction on these inputs and checks the earlier examples too.

Build a construction in the workspace above first. This case will test those pieces.

Where would you make a change if a third thermometer needed a different correction, and which components could remain?

Keep the device-specific work outside the calculation that uses its results.

The correction is supplied for these invented thermometers; the workshop does not estimate a real calibration. It illustrates composing calculations. The Python examples introduce replaceable source and sink objects.

Continue the courseFail Fast, Fail Early →
← Dataclasses and Record Ownership