Final Capstone: Build a Quiz Engine · practice
Present the Final Result
The engine can now return a score. Give the complete run a beginning and an end.
Add two focused
score_message(score, total)formats one result line;run_quiz(plan)presents the title, runs the questions, prints the final report, and returns the score.
Format from values
A score message should work for any quiz length:
def score_message(score, total):
return f"{score} out of {total} correct."
The function should use its
With score = 2 and total = 3, the result is:
2 out of 3 correct.
Let the orchestrator read like a story
A high-level function is easiest to read when its calls describe the stages:
show the title
run all questions
show the final heading
show the score message
return the score
The detailed
Return even after printing
run_quiz(plan) prints the player experience, but it should also return the final score.
The
Preserve spacing deliberately
Use a blank line before the first question and before FINAL SCORE. The question loop already prints its own leading blank line, so the high-level function does not need another one there.
The output should finish with the score message. Avoid temporary diagnostics in the final experience.
Test the whole path
At this point, one test call crosses several boundaries:
run_quiz
-> run_questions
-> ask_question
-> read_nonempty_answer
-> response_result
If the end-to-end result fails, use the focused checks from earlier milestones to identify which layer broke.
Why should run_quiz(plan) return the score after printing the final report?
Task
Add the final presentation layer.
Implement score_message(score, total) so it returns:
SCORE out of TOTAL correct.
Implement run_quiz(plan) so it:
prints
QUIZ: TITLE;calls
run_questions(plan);prints a blank line and
FINAL SCORE;prints
score_message(score, number_of_questions);returns the integer score.
Keep all earlier
To try this function with Run, temporarily add this call below the definitions and existing assertions:
print(run_quiz(build_quiz_plan()))
Check the title, feedback, and final report. This temporary print displays the returned score once more after the report so you can compare it.
Remove the temporary call before Submit and before continuing. Keep the noninteractive assertions; they check the helpers without asking for input.