🐸

The Cabinet Check

The Data Tinkererpython-data-tinkerer-28-the-cabinet-check
Reward: 145 XP
|

The Cabinet Check

Hoppy stands in front of the data cabinet with three different things spread across the table: one free-form clue note, one tidy guard record with named fields, and one stock table arranged in rows and columns.

This checkpoint is not trying to test how many terms you memorized. It wants to confirm a more real skill: when different shapes of information appear together, can you tell which format fits each one, and can you still pull one useful detail out of every format?

Not every kind of information belongs in the same format

Plain text fits free description. JSON fits one record with named fields. CSV fits repeated rows in a table. Real data work is not only about reading data. It is also about judging which shape makes sense for the information you have.

camp_note = "Lanterns ready at dusk."
keeper_record = {"guide": "Pip", "room": "Moss Shelf"}
stock_sheet = "item_name,count
fern rope,2
moon lamp,1"

note_format = "text"
record_format = "json"
sheet_format = "csv"

print(note_format, record_format, sheet_format)

This small example is only here to reset your instinct for the three formats. It is not the full starter answer. In the real task, you will do two things at once on three real samples: choose the format and pull one tiny detail out of each one.

Today's task: choose formats for three samples, then do one light整理 step

The starter already reads three small samples for you: cabinet_note.txt, guard_record.json, and stock_table.csv. Your job is to choose the best format label for each one, pull one small detail from each sample, and then gather everything into cabinet_plan.

1
Notice how the three samples differ in shape

Run the starter and look first: the note is free text, the guard record is one structured record with named fields, and the stock table repeats the same kind of row.

2
Choose the best format for each kind of information

Set clue_note_format, guard_record_format, and stock_table_format to the most suitable labels.

3
Pull one tiny detail from each format

Read note_first_line from the note, keeper_name from the JSON record, and first_item_name from the first CSV data row.

4
Gather the checkpoint result into cabinet_plan

Build cabinet_plan from those choices and extracted details. That makes this a light combined task: compare formats, do a little reading, then gather the result.

Keep the checkpoint light

This lesson only checks Chapter 4's basic judgment and light handling: plain text, JSON, and CSV usage differences, plus one simple detail from each. We are not building a big project or moving into APIs or local filesystem topics.

Suggested Solution
Expand
Solution:
import json

with open("cabinet_note.txt", "r", encoding="utf-8") as file:
  note_text = file.read().strip()

with open("guard_record.json", "r", encoding="utf-8") as file:
  guard_record = json.load(file)

with open("stock_table.csv", "r", encoding="utf-8") as file:
  stock_csv_text = file.read().strip()

print("Note text:")
print(note_text)
print("Guard record:", guard_record)
print("Stock table:")
print(stock_csv_text)

stock_rows = stock_csv_text.splitlines()

clue_note_format = "text"
guard_record_format = "json"
stock_table_format = "csv"
note_first_line = note_text.splitlines()[0]
keeper_name = guard_record["keeper_name"]
first_item_name = stock_rows[1].split(",")[0]

cabinet_plan = {
  "clue_note_format": clue_note_format,
  "guard_record_format": guard_record_format,
  "stock_table_format": stock_table_format,
  "note_first_line": note_first_line,
  "keeper_name": keeper_name,
  "first_item_name": first_item_name
}

print("Clue note format:", clue_note_format)
print("Guard record format:", guard_record_format)
print("Stock table format:", stock_table_format)
print("Note first line:", note_first_line)
print("Keeper name:", keeper_name)
print("First item name:", first_item_name)
print("Cabinet plan:", cabinet_plan)
Advanced Tips
Want more? Click to expand

The main thing this checkpoint wants to confirm is not that you memorized names. It is that you are starting to build structure-choice instinct: free text, single records, and repeated tables fit different forms.

At this point, Chapter 4 has closed its basic format loop. If the course continues, the next chapter should move into more realistic text-detective situations.

Loading...
Terminal
Terminal
Ready to run...