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

Read Counts and Point Out the Bad Fields

Coding challenges

BOTIE

Return one item per field: numbers for readable decimal text, unchanged text for fields that cannot be read.
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 one item per field: numbers for readable decimal text, unchanged text for fields that cannot be read.

The import contains ["8", "3", "5"]. Read them as [8, 3, 5] and report no rejected fields. A later import can contain unreadable text or a negative count. Keep usable counts and identify the original positions needing correction.

Inspect the component calculation
Read whole numbers(
  Count fields as text: Count fields as text
)
Examples and results
Count fields as text
  1. 0"8"
  2. 1"3"
  3. 2"5"
Required result
  1. 08
  2. 13
  3. 25
Count fields as text
  1. 0"8"
  2. 1unknown
  3. 2"5"
Required result
  1. 08
  2. 1unknown
  3. 25
Count fields as text
  1. 0bad
  2. 1"0"
  3. 2later
  4. 3"4"
Required result
  1. 0bad
  2. 10
  3. 2later
  4. 34
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 local parser accepts small decimal whole-number text. The Python exercises use int() and actual exceptions; this workshop makes their accepted and rejected paths visible. 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 Invalid Fields Move

This check uses the pieces from “Keep the Fields in Order”.

BOTIE

The next import is ["later", "0", "9", "missing"]. Read the current fields, keeping zero as a valid count and preserving original positions.
Count fields as text
  1. 0later
  2. 1"0"
  3. 2"9"
  4. 3missing

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 must positions refer to the original fields rather than the shorter accepted list?

Keep an error attached to the data that caused it.

The local parser accepts small decimal whole-number text. The Python exercises use int() and actual exceptions; this workshop makes their accepted and rejected paths visible.

Continue the courseMutation and Copies →
← Pydantic Constraints and Validators