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

Keep Each Report's Notes Separate

Coding challenges

BOTIE

Create a report for each greenhouse, then add the supplied note to the named greenhouse only. Return rows containing house and tags. Other greenhouses must keep empty notes lists.
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

Create a report for each greenhouse, then add the supplied note to the named greenhouse only. Return rows containing house and tags. Other greenhouses must keep empty notes lists.

Botie is adding notes to greenhouse reports. An empty notes list can be a new object for each report or the same object reused by several reports.

Create the notes lists has a choice between reusing one list and creating a new list for each report. Attach notes to their reports pairs those lists with greenhouse names. Add a note to one greenhouse then updates the named report. With only north in the first example, try either list choice and inspect the result.

Examples and results
Greenhouses needing reports
  1. 0north
Greenhouse receiving the note
north
Note to add
checked
Required result
  1. house
    north
    tags
    ["checked"]
Greenhouses needing reports
  1. 0lab
Greenhouse receiving the note
lab
Note to add
review
Required result
  1. house
    lab
    tags
    ["review"]
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 records illustrate the ownership of mutable defaults; they are not Python dataclass instances and do not validate Python annotations. Each run uses a private copy so repeated tests leave the source data unchanged. Numerical tests allow a difference of 0.001. Lists and structures must also have the right shape.

The Middle Report Receives the Note

This check uses the pieces from “Create Reports and Add One Note”.

BOTIE

There are now east, west and roof reports. The recalibrated note belongs to west only; east and roof have no notes.
Greenhouses needing reports
  1. 0east
  2. 1west
  3. 2roof
Greenhouse receiving the note
west
Note to add
recalibrated
Should adding the note to west also add it to east? Answer true or false.

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 did the one-report example fail to expose the shared-list mistake?

Test changes to one object while another object exists. Equal initial values do not establish independent ownership.

The records illustrate the ownership of mutable defaults; they are not Python dataclass instances and do not validate Python annotations. Each run uses a private copy so repeated tests leave the source data unchanged.

Continue the courseComposition and Interchangeable Components →
← Missing Values, Defaults, and None