Show Stats

Add a show_stats function and display it at the start of each round

💻

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

STATS is now being updated after every round — but the player never sees it. A show_stats function displays the current session numbers at the top of each round, so the player can see their progress before choosing a category.

Calling show_stats at the start of the while loop means the player sees their stats before every round:

Games played: 3
Best round: 8/10
Total correct: 21 out of 30

The first time through, STATS["games"] is 0 — so you need a guard to skip the display until at least one round has been completed.

Instructions

Add show_stats and call it at the top of the while loop.

  1. Before run_quiz, define a function named show_stats with no parameters. Inside:
    • If STATS["games"] == 0, print "No games played yet." and return — this prevents a display with all zeros before the first round.
    • Otherwise, print the following three lines:
      • f"Games played: {STATS['games']}"
      • f"Best round: {STATS['best_score']}/{STATS['best_total']}"
      • f"Total correct: {STATS['total_correct']} out of {STATS['total_questions']}"
  2. At the very top of the while True: loop (before print("Categories: ...")), call show_stats() and then print() — the blank line separates the stats from the category prompt.