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 Validation and Error Handling

Check the Interval and Number of Readings

Coding challenges

BOTIE

Return the lower and upper endpoints when they are in increasing order. Return "Lower must be below upper" when they are reversed or equal.
Ready to test
0 passed · 0 failed · 3 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

Return the lower and upper endpoints when they are in increasing order. Return "Lower must be below upper" when they are reversed or equal.

A capture asks for 4 readings between 2 and 9. The lower endpoint must be below the upper endpoint, and the count must be a whole number from 1 through 20.

Inspect the component calculation
Check the capture interval(
  Lower and upper endpoints: Capture interval
  Endpoint order: increasing
)
Examples and results
Capture interval
lower
2
upper
9
Required result
lower
2
upper
9
Capture interval
lower
-2
upper
5
Required result
lower
-2
upper
5
Capture interval
lower
0
upper
1
Required result
lower
0
upper
1
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 workshop checks the interval and count only. Real Pydantic, nested fields and strict Python numeric types are tested in the coding challenges. 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 Boolean Arrives as the Count

This check uses the pieces from “Check the Two Requirements”.

BOTIE

The interval now runs from -5 to 5, but count is true. Keep the same whole-number count rule from 1 through 20.
Capture interval
lower
-5
upper
5
Requested number of readings
true
Does count:true satisfy the requested-count rule?

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.

Why can the count pass while the complete capture still fails?

A request must meet every requirement that applies to it.

This workshop checks the interval and count only. Real Pydantic, nested fields and strict Python numeric types are tested in the coding challenges.

Continue the coursePython Exceptions →
← Pydantic Models and Optional Fields