Add the Stats Dictionary
Exit

Add the Stats Dictionary

Create the STATS dictionary and make run_quiz return score and total

💻

Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.

Two small changes set up the stats system: add the STATS dict to hold the counters, and add return score, total to run_quiz so the while loop can read the results.

Neither change affects how the quiz plays — STATS starts at all zeros and the return value is not yet used by the caller. You will wire them together in the next chapter.

Instructions

Add the STATS dictionary and make run_quiz return its results.

  1. After QUESTIONS, define a dictionary named STATS with five keys — each initialized to 0:
    • "games" — how many rounds have been completed
    • "best_score" — the highest number of correct answers in a single round
    • "best_total" — how many questions were in that best round
    • "total_correct" — cumulative correct answers across all rounds
    • "total_questions" — cumulative questions answered across all rounds
  2. At the end of run_quiz, after calling show_results(score, total), add return score, total — the function now hands both values back to the caller so they can be recorded in STATS.