Dataclasses and Value Objects · practice
Keep Class-related Helpers Close
Some helpers belong closely to a class’s subject but need neither an
Converting a raw
A static method receives nothing automatically
@staticmethod leaves the self and no cls. It can be called through the class:
Duration.split_seconds(150)
Why is split_seconds a static method rather than a class method?
A module function is also honest
This kind of helper could be written outside the class:
def split_seconds(total):
return total // 60, total % 60
That version is equally testable and often easier to reuse. Keep a static
The choice is organizational, not magical. Static methods gain no access and no special performance.
The exercise adds one class-related helper and routes correctness through it. The alternative constructors from the previous lesson are already complete so only this decision is graded.
Task
Add Question.normalize(response) as a static
Update Question.is_correct(response) to normalize both the response and stored answer, so " DEF " matches "def".
The existing alternative constructors are complete. Do not change their construction behavior. Keep Question’s __post_init__ validation intact.