Good place to stop if you're short on time — step 3 picks up here.
Lesson idea Tap to fold
What should a validator return for an impossible score?
Show the answer
False, None, or a structured failure—never a silently accepted value.
A passing message is not a meaningful test
assert evaluates a condition and raises AssertionError when false. A later success print only runs if every preceding assertion passes. Check ordinary cases, both boundaries and invalid types. bool is a subclass of int, so isinstance(score, int) alone accepts True; explicitly exclude bools when the schema requires an integer score.
Repairing the score rule is only half of the change task: add an assertion that rejects zero. The validator task needs a typed dictionary, a nonempty stripped string item_id and exact pass/fail label, plus three assertions for a valid row, missing ID and invalid label. The course checks run your assertions against broken rules; assert True cannot establish test coverage.
Python can remove assert statements under optimization (-O). Use assertions for tests and developer invariants, not required input validation, authorization or security controls. The validator itself returns a boolean using explicit conditions. These small checks are a starting point, not proof that a system is bug-free; later Studio projects use fuller test suites.
# Validate explicitly; use assertions to test the rule.
def valid_score(score):
return (isinstance(score, int)
and not isinstance(score, bool)
and 1 <= score <= 5)
assert valid_score(1) is True
assert valid_score(5) is True
assert valid_score(0) is False
assert valid_score(True) is False
assert valid_score(1.5) is False
print("Boundary and type tests passed")
Both allowed boundaries pass, while zero, True and 1.5 are rejected by the actual validator.
An assertion should fail when the behavior it protects is broken. Do not catch AssertionError just to print success.
Predict, explain, then test
These three comparisons are self-reviewed, not scored. Coding checks run new inputs; the section quiz records separate knowledge evidence.
Catch a boundary
A rule accepts zero, but only tests one and five. What is missing?
Compare your answer · self-reviewed
An assertion that zero is rejected; the existing tests cannot detect the wrong lower boundary.
Inspect bool
Why exclude bool explicitly from integer scores?
Compare your answer · self-reviewed
True is an int subclass and otherwise passes the 1–5 range check.
Use assertions safely
Can required authorization depend on assert?
Compare your answer · self-reviewed
No. Optimization can remove assertions; required validation/security must use explicit checks.
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.