// python · beginner project

Python Project: Make a Quiz Game with Scores and a High Score

Build a multiple-choice quiz game in Python with shuffled questions, input checking, a final score and a saved high score. A fun beginner project using lists, dictionaries and functions.

Quiz games are a brilliant first project: they’re short, easy to test, and you can fill them with questions about anything you like. In this project you’ll build a multiple-choice quiz that shuffles its questions, checks answers, keeps score, and saves a high score to a file. It’s a small version of the idea behind our own PyQuest game.

Here’s a round of the finished game:

output
Question 1 of 4
Which keyword creates a function in Python?
  A) func
  B) def
  C) function
  D) lambda
Your answer: b
Correct!

...

You scored 3 out of 4 (75%).
New high score!

Step 1: Store the questions

Each question has the question text, some options, and the correct answer, so a dictionary is a natural fit. The quiz is a list of them:

python
QUESTIONS = [
    {
        "question": "Which keyword creates a function in Python?",
        "options": ["func", "def", "function", "lambda"],
        "answer": "B",
    },
    {
        "question": "What does len('code') return?",
        "options": ["3", "4", "5", "An error"],
        "answer": "B",
    },
    {
        "question": "Which of these is a list?",
        "options": ["(1, 2)", "{1, 2}", "[1, 2]", "'1, 2'"],
        "answer": "C",
    },
    {
        "question": "What is 7 // 2 in Python?",
        "options": ["3.5", "3", "4", "1"],
        "answer": "B",
    },
]

Keeping the questions separate from the game logic means you can add new ones without touching any other code.

Step 2: Ask one question

python
LETTERS = "ABCD"

def ask(question, number, total):
    print(f"\nQuestion {number} of {total}")
    print(question["question"])
    for letter, option in zip(LETTERS, question["options"]):
        print(f"  {letter}) {option}")

    while True:
        answer = input("Your answer: ").strip().upper()
        if answer in LETTERS and answer != "":
            break
        print("Please type A, B, C or D.")

    if answer == question["answer"]:
        print("Correct!")
        return True
    correct_letter = question["answer"]
    correct_text = question["options"][LETTERS.index(correct_letter)]
    print(f"Not quite. The answer was {correct_letter}) {correct_text}")
    return False

A few things worth noticing:

  • zip(LETTERS, options) pairs each letter with an option: ("A", "func"), ("B", "def") and so on.
  • .strip().upper() means b, B and b are all accepted (see the strings guide).
  • The while loop keeps asking until the answer is valid. We also check answer != "", because the empty string counts as being in every string!
  • When the answer is wrong, we show the correct one. Explaining mistakes is what makes a quiz useful for learning.

Step 3: Run the whole quiz

python
import random

def run_quiz(questions):
    order = questions.copy()
    random.shuffle(order)
    score = 0
    for number, question in enumerate(order, start=1):
        if ask(question, number, len(order)):
            score += 1
    return score

We shuffle a copy, so the original list stays in its written order. The lists guide explains why order = questions wouldn’t make a copy. ask returns True or False, so we can add to the score directly.

Step 4: Save a high score

Using what you learned in the files guide:

python
HIGH_SCORE_FILE = "quiz_highscore.txt"

def load_high_score():
    try:
        with open(HIGH_SCORE_FILE, encoding="utf-8") as f:
            return int(f.read())
    except (FileNotFoundError, ValueError):
        return 0

def save_high_score(score):
    with open(HIGH_SCORE_FILE, "w", encoding="utf-8") as f:
        f.write(str(score))

Step 5: Put it together

python
def main():
    print("=== CodeRunner Python Quiz ===")
    high = load_high_score()
    print(f"Current high score: {high}")

    score = run_quiz(QUESTIONS)
    total = len(QUESTIONS)
    percent = round(score / total * 100)
    print(f"\nYou scored {score} out of {total} ({percent}%).")

    if score > high:
        print("New high score!")
        save_high_score(score)

    if percent == 100:
        print("Perfect! You're ready for harder questions.")
    elif percent >= 50:
        print("Good effort! Review the ones you missed and try again.")
    else:
        print("Keep going. Every attempt helps it stick.")

if __name__ == "__main__":
    main()

Save everything in quiz.py in this order: imports, the constants (QUESTIONS, LETTERS, HIGH_SCORE_FILE), the functions, then the if __name__ == "__main__": lines. Run it with:

terminal
python quiz.py

Testing checklist

  • Type lower-case letters, spaces, E, a number and nothing at all. Only A–D should be accepted.
  • Get every answer right, then every answer wrong.
  • Delete quiz_highscore.txt and run it again; it should start from 0.
  • Run it a few times and check the questions come in a different order.

Ideas to extend it

  1. Load questions from a file. Save QUESTIONS as JSON (see the to-do project) so you can write new quizzes without editing code.
  2. Add explanations. Give each question an "explain" key and print it after every answer.
  3. Topics. Let the player choose a topic, such as Lists or Strings, before starting.
  4. Timer. Use time.time() before and after each answer to award bonus points for speed.
  5. Retry mistakes. Keep a list of missed questions and offer to ask them again at the end.

What you practised

Storing structured data in lists of dictionaries, writing functions that return values, validating input in a loop, shuffling with the random module, and saving data to a file. Each extension above adds one more skill.

Want to see how far a quiz like this can go? Play PyQuest: 250 questions, streaks, XP and an explanation after every answer.