Python Design and Type Hints
Check the Values Entering the Converter
BOTIE
Examples, experiments and workspace controls
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.
Context for this challenge
Keep actual finite numerical readings, then convert them from Celsius to Fahrenheit. Leave out text, booleans and null. Keep zero and repeated numerical readings. Return the converted temperatures in their original order.
The Celsius-to-Fahrenheit converter works on numbers. Botie needs to decide what enters it when a file supplies other kinds of values.
Keep numerical readings passes actual numbers through unchanged and leaves other values out. Put it before the familiar Multiply and Add conversion. In the first example all readings are numerical, so the check should leave [0, 20] intact.
Examples and results
- Incoming Celsius values
- 00
- 120
- Celsius-to-Fahrenheit multiplier
1.8
- Fahrenheit offset
32
- Required result
- 032
- 168
- Incoming Celsius values
[]
- Celsius-to-Fahrenheit multiplier
1.8
- Fahrenheit offset
32
- Required result
[]
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
This construction checks values while it runs. It does not execute a static type checker. The deliberate policy here skips unusable values; a later lesson will require rejecting an entire invalid batch. Numerical tests allow a difference of 0.001. Lists and structures must also have the right shape.
Repeated and Fractional Readings
This check uses the pieces from “Check Readings before Converting Them”.
BOTIE
- Incoming Celsius values
- 04.5
- 1false
- 24.5
- 3-40
- Celsius-to-Fahrenheit multiplier
1.8
- Fahrenheit offset
32
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.
What information does a type hint give another programmer, and what extra work does the running value check perform?
State the expected values in the interface and choose an explicit response when incoming data does not match.
This construction checks values while it runs. It does not execute a static type checker. The deliberate policy here skips unusable values; a later lesson will require rejecting an entire invalid batch.