Python Design and Type Hints
Use One Alert Limit for Both Reports
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
Use Keep readings at or above the limit followed by Count items, as in the previous workshop. With morning readings [18, 24, 27] and a limit of 24, the result is 2.
The morning readings are [18, 24, 27] degrees Celsius and the evening readings are [24, 28]. Both reports must use the same alert limit. At 24 degrees, each report contains two alerts.
Inspect the component calculation
Count items(
Items: Keep readings at or above the limit(
Temperature readings: Morning Celsius readings
Alert limit: Shared alert limit in Celsius
)
)Examples and results
- Morning Celsius readings
- 018
- 124
- 227
- Shared alert limit in Celsius
24
- Required result
2
- Morning Celsius readings
[]
- Shared alert limit in Celsius
15
- Required result
0
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 shared wire makes one policy visible. In Python, DRY also concerns the shared calculation and other knowledge that must stay consistent. 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.
A Shared Limit Below Zero
This check uses the pieces from “Connect the Evening Report to the Same Limit”.
BOTIE
- Morning Celsius readings
- 0-3
- 1-2
- 21
- Evening Celsius readings
- 0-5
- 1-4
- Shared alert limit in Celsius
-2
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.
If the morning report later gets a genuinely different policy, why would sharing that limit become the wrong design?
Share a rule because it must stay consistent, rather than because two current numbers happen to be equal.
The shared wire makes one policy visible. In Python, DRY also concerns the shared calculation and other knowledge that must stay consistent.