Good place to stop if you're short on time — step 3 picks up here.
Lesson idea Tap to fold
Why did Day 13 use int(parts[1])?
Show the answer
split() returns text. int() converts the frame field into a number.
Recover from expected bad data, not every failure
int("unknown") raises ValueError because the text does not describe an integer. A try block attempts that risky operation; except ValueError names the expected failure and its fallback. Keep the guarded operation small so you know what failed.
Put the guard inside a loop when one bad row should be reported and the next row should still run. An empty list has no rows to report. "0" is valid numeric text, not a failed conversion. Negative integer text also converts; whether a negative count is acceptable is a separate domain rule.
Do not catch every exception just to get a quiet report. A misspelled variable raises NameError and an unexpected None argument to int raises TypeError. Those programming/caller errors should remain visible under this exercise’s policy.
# Attempt each row independently.
raw_values = ["96", "unknown", "0"]
for raw in raw_values:
try:
frames = int(raw)
except ValueError:
print("Skipped bad row")
else:
print(frames)The lines are 96, Skipped bad row and 0. try/except/else runs else only when the conversion succeeds; the existing exercises may print inside try instead. Both can preserve this behavior.
Watch a batch continue, repair the exception name, fill a narrow guard, then write your own conversion policy. Test valid zero as well as invalid text.
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.
Distinguish zero
Should int("0") take the ValueError fallback?
Compare your answer · self-reviewed
No. Zero is a valid integer. Bad numeric text is not the same as a valid zero value.
Place the guard
Why keep try/except inside the loop instead of around the entire batch?
Compare your answer · self-reviewed
An expected bad row is handled individually and the next row is still attempted. Catching outside the loop abandons the remaining iterations.
Catch narrowly
Should except Exception hide a misspelled variable name?
Compare your answer · self-reviewed
No. NameError is a programming error, not invalid numeric text. Catch the expected ValueError; let unrelated failures remain visible.
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.
The tutor mounts here when JavaScript is available. The lesson above stays readable without it.