Good place to stop if you're short on time — step 3 picks up here.
Which string method removes spaces from the beginning and end?
strip().
How do you retrieve the frame count from a dictionary named shot?
shot["frames"].
Why did Day 13 use int(parts[1])?
split() returns text. int() converts the frame field into a number.
Why catch ValueError around int(raw), but leave NameError visible?
ValueError is the expected conversion failure for malformed numeric text. NameError is a programming mistake; hiding it would conceal a broken variable name.
Record which ideas needed assistance and revisit their lessons. Self-review is not a scored correct answer.
Trace a valid two-field parser, rebuild it, repair its error-state lookup, then write an independent three-field parser that follows a new validation policy.
If the rebuild is hard, that is information — not failure.
Lesson idea Tap to fold
Name the method that removes outside spaces, the container with labelled keys, the method that cuts on a separator, and the exception raised by int("unknown").
Show the answer
strip(), a dictionary, split(), and ValueError.
Defend the record contract on unfamiliar data
A useful parser returns data the caller can inspect, not just a report that looks right. Revisit cleaning, splitting, integer conversion and dictionaries together. The two-field example below assumes a valid number; ValueError remains visible if that precondition is broken.
The rebuild preserves the two-field function’s contract. The repair uses a separate error boolean because frames 0 could mean either valid zero or its labelled fallback. The final independent task introduces a new, explicit three-field policy: None means no accepted record, while a valid dictionary can contain zero.
Before the transfer, note four tools: len(parts) counts fields; isinstance(line, str) checks the argument’s type; raise TypeError exposes a wrong caller type; status in ("approved", "review", "hold") tests membership. Return None for malformed strings, not for unrelated caller mistakes.
# Return data from a valid two-field example.
def parse_shot(line):
parts = line.strip().split("|")
return {"name": parts[0].strip(),
"frames": int(parts[1])}
# Keep reporting at the caller.
shot = parse_shot(" Museum | 0 ")
print(shot["name"], "·", shot["frames"], "frames")The report is Museum · 0 frames. A dictionary with integer zero is a valid result. It is different from None, which the new transfer policy uses to mean no accepted record.
Trace, rebuild and repair before tackling the new three-field parser. Then use the scored checkpoint to identify concepts to revisit; the score does not award the practical check.
Predict, explain, then test
These three brief checks are self-reviewed, not a scored quiz. Explain your answer before opening the comparison. Coding checks test the stated data contract on unfamiliar inputs.
Trace the return
What must a parser return so its caller can inspect frames numerically?
Compare your answer · self-reviewed
A dictionary containing an integer frames value. A printed line or a dictionary with string frames is not equivalent.
Read error evidence
A repair helper returns frames 0 for both valid zero and failed conversion. Which field distinguishes them?
Compare your answer · self-reviewed
The separate error boolean. Testing the count alone would wrongly discard a valid zero.
Defend a new policy
Why return None for malformed text but raise TypeError for a non-string call in the transfer task?
Compare your answer · self-reviewed
Malformed text is an expected data failure under this policy. A non-string argument violates the function API; hiding that mistake as a skipped row makes debugging harder.
Independent transfer: a safe record parser
Write parse_record(line) for the simple training format name|frames|status. This is not quoted CSV. Apply these rules in your own implementation:
- Accept a string; raise
TypeErrorfor any other argument type. - Require exactly three fields. Trim their outside whitespace and preserve the name’s case.
- Require a nonempty name. Convert frames with
int(); accept zero, but reject negative counts. - Lowercase status and allow only
approved,revieworhold. - Return a dictionary with name, integer frames and status for valid data. Return
Nonefor malformed strings. - Catch the expected
ValueErrorclose to conversion. Do not hide caller errors with a broad exception handler.
Select this task in the exercise controls. The checkpoint link opens its brief and selects its unfinished starter; it never runs Python or awards a pass for you. Review narrow exception handling if needed.
Read the unfinished starter without running Python
# Parse a new three-field record from this brief.
def parse_record(line):
# Replace this unfinished return with your parser.
return None
# Report the valid result, then an invalid row.
shot = parse_record(" Museum | 0 | APPROVED ")
if shot is not None:
print(shot["name"], "·", shot["frames"], "·",
shot["status"])
else:
print("Skipped bad row")
print(parse_record("Canal|many|hold"))
Sample output: Museum · 0 · approved, then None on a separate line. The checks try new names, whitespace, zero, missing/extra fields, invalid numbers and wrong caller types. Quiz scores and this practical evidence are separate.
Choose an exercise to load its prompt.
Loading exercises…
Noted on your route map, with the step you were on. Nothing is lost by parking it — the next review day will bring this idea back, and the flag tells the course where to slow down.
Section 3 checkpoint
Answer five questions, then review the explanations and targeted refresher links. The quiz does not award the independent parser check, and tutor login is not required.
The tutor mounts here when JavaScript is available. The lesson above stays readable without it.