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

Use One Alert Limit for Both Reports

Coding challenges

BOTIE

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.
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

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
  1. 018
  2. 124
  3. 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

Both reports now use a limit of -2 degrees Celsius. The morning readings are [-3, -2, 1], while the evening readings are [-5, -4].
Morning Celsius readings
  1. 0-3
  2. 1-2
  3. 21
Evening Celsius readings
  1. 0-5
  2. 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.

Continue the courseType Hints and Function Contracts →
← Functions with Clear Responsibilities