Build a Python Quiz Game

Build a terminal Python quiz with validation, scoring, and replay.

Introduction

30 Second Summary

A quiz feels simple until it has to understand messy answers or keep score across several questions. Those small details reveal the building blocks behind interactive programs.

In this project, you will build a terminal quiz using Python. It asks three questions before showing a score with feedback based on the result.

What You'll Build

Run your finished quiz to answer three Python questions before the terminal reveals your score with a tailored result message.

By the end of this project, you'll have:

  • A three-question terminal quiz that reads structured question data to give immediate feedback after each answer.
  • A validated input flow that accepts `A` or `a` even when spaces surround the answer.
  • A final result that shows the player's score as a percentage before giving tailored feedback.
  • A Secret Mission: Add a validated replay loop so players can retake the quiz without restarting the file.

Are there any prerequisites?

You need a computer running Windows 10 or newer with internet access. No programming experience is required because the first step guides you through the full coding setup.

Before We Start

Before the hands-on work begins, take a moment to define what your Python quiz will do. Connecting the game to your reason for building it gives the project a clear goal.

Set Up Python and Visual Studio Code

Your quiz needs Python 3.14.7 to execute each line of code. Visual Studio Code gives you one place to write the file.

The Python extension for Visual Studio Code connects the editor to the selected interpreter. This step proves that connection by running quiz_game.py.

In this step, get ready to:
  • Confirm Windows compatibility before installing Python 3.14.7.
  • Prepare Visual Studio Code with the Microsoft Python extension.
  • Run a saved quiz_game.py starter file.
Install Python 3.14.7

Python 3.14 supports Windows 10 or newer. Checking your Windows version first prevents an incompatible installation.

  • Press the Windows key to open Windows search.
  • Type Settings into the search bar.
  • Press Enter to open Settings.
  • Select System from the Settings sidebar.
  • Select About from the System page.
  • Confirm that the Windows specifications show Windows 10 or newer.

Your computer is compatible when the edition shows Windows 10 or a newer Windows release.

The Python Install Manager handles the interpreter installation on Windows. It also provides the py command used throughout this setup.

  • Open the official Python downloads page in your browser.
  • Choose the Python Install Manager option for Windows.
  • Run the downloaded installer.
  • Complete the installation using the recommended selections.

The installer confirms when Python Install Manager is ready. You can now ask it for the exact Python release used by this quiz.

  • Press the Windows key to open Windows search.
  • Type PowerShell into the search bar.
  • Press Enter to open a fresh PowerShell terminal.
  • Install Python 3.14 by running this command:
py install 3.14

What does this command do?

The command asks Python Install Manager to install the Python 3.14 release. This project uses Python 3.14.7.

Can't run the install command?

  • Return to the official Python downloads page if Python Install Manager did not finish installing.
  • Close PowerShell after completing the installer.
  • Open a fresh PowerShell terminal so Windows can find the new command.

Ask for help: Help me check why Python Install Manager is unavailable in my fresh PowerShell terminal.

  • Close the current PowerShell terminal.
  • Return to Windows search to open a fresh PowerShell terminal.

Before you check, which exact Python version do you expect the fresh terminal to report?

  • Verify the installed interpreter by running this command:
py -3 --version

What does this command check?

The command displays the installed Python 3 version. Running it in a fresh terminal confirms that Windows can find the interpreter.

You'll see Python 3.14.7 when the correct interpreter is ready.

✔️ I see Python 3.14.7

That's the interpreter ready. Your fresh PowerShell terminal can find the exact Python release used by the quiz.

ⓧ I see an older version

An older interpreter cannot confirm this project's setup. Install Python 3.14 through Python Install Manager.

  • Install the required Python release by running this command:
py install 3.14

What does this command do?

Python Install Manager installs the Python 3.14 release. The existing older interpreter can remain installed.

  • Close the current PowerShell terminal.
  • Return to Windows search to open a fresh PowerShell terminal.
  • Check the installed version again by running this command:
py -3 --version

What does this command check?

The version check confirms which Python 3 interpreter the fresh terminal can find.

You'll see Python 3.14.7 when the required version is available.

ⓧ The command is unavailable

Windows needs Python Install Manager before the py command becomes available.

  • Return to the official Python downloads page.
  • Install Python Install Manager using the Windows option.
  • Return to Windows search to open a fresh PowerShell terminal.
  • Install the required Python release by running this command:
py install 3.14

What does this command do?

Python Install Manager downloads the Python 3.14 interpreter used by this project.

  • Close the current PowerShell terminal.
  • Return to Windows search to open another fresh PowerShell terminal.
  • Verify the installation by running this command:
py -3 --version

What does this command check?

The version check proves that the fresh terminal can now find Python.

You'll see Python 3.14.7 after the installation succeeds.

Install Visual Studio Code and the Python extension

Visual Studio Code provides the editor for your quiz. The Microsoft Python extension adds interpreter selection plus the Run Python File control.

Why Visual Studio Code?

IDLE offers a smaller editor that comes with Python. Visual Studio Code gives you an editor workflow that transfers to larger projects.

The Python extension connects that workflow to your installed interpreter. You can write the file plus run it from the same window.

  • Open the official Visual Studio Code setup page in your browser.
  • Select the Windows User setup download.
  • Run the downloaded Visual Studio Code installer.
  • Complete the setup wizard using its recommended selections.

User setup does not require administrator permissions. The completed wizard confirms that the editor is installed.

  • Press the Windows key to open Windows search.
  • Type Visual Studio Code into the search bar.
  • Press Enter to open the editor.

You'll see the Visual Studio Code editor window. The extension comes next because it teaches the editor how to work with Python files.

  • Press Ctrl+Shift+X to open Extensions.
  • Enter Python in the Extensions search field.
  • Select the Python extension published by Microsoft.
  • Click Install on the extension page.

The extension page shows its installed state when setup finishes. Visual Studio Code can now discover your Python interpreters.

The interpreter picker can look crowded when several Python entries are present. Choose the entry that displays the exact project version.

  • Press Ctrl+Shift+P to open the Command Palette.
  • Enter Python: Select Interpreter in the Command Palette.
  • Select the interpreter labelled Python 3.14.7.

Visual Studio Code now uses Python 3.14.7 for the files you run in this project.

Can't find the interpreter?

  • Confirm that the version command reported Python 3.14.7 in a fresh PowerShell terminal.
  • Close Visual Studio Code after installing Python.
  • Reopen Visual Studio Code before checking the interpreter list again.

Ask for help: Help me make Python 3.14.7 appear in the Visual Studio Code interpreter picker.

Create and run the starter file

A file ending in .py tells Visual Studio Code to interpret the file as a Python program. Your first line prints a visible setup message in the terminal.

  • Click File in the Visual Studio Code top menu.
  • Select Open Folder.
  • Select your Desktop in the folder picker.
  • Use the folder picker's New folder control to create python-quiz.
  • Select the python-quiz folder.
  • Click Select Folder to open it in Visual Studio Code.

The Explorer sidebar now shows python-quiz as the open folder.

  • Click the New File control in the Explorer sidebar.
  • Enter quiz_game.py as the filename.
  • Press Enter to create the file.
  • Add the starter message to quiz_game.py by pasting this code:
print("Quiz ready!")

What does this code do?

The print() function sends text to the terminal. The quoted text is the exact message Python displays.

  • Press Ctrl+S to save quiz_game.py.

Before you run the file, what message do you expect the single print line to send to the terminal?

  • Click the Run Python File play button in the top-right corner of the editor.

You'll see Quiz ready! in the Visual Studio Code terminal. Your editor can now run the saved Python file with the selected interpreter.

Don't see the starter message?

  • Confirm that quiz_game.py is the active file in the editor.
  • Check that the file contains the same capitalization plus punctuation as the code block.
  • Save the file before selecting Run Python File again.

Ask for help: Help me debug why quiz_game.py does not print Quiz ready in the Visual Studio Code terminal.

✔️ Awesome, I've got everything!

Great. Double check that quiz_game.py is saved inside python-quiz before moving on.

ⓧ I'd like to double check the full code

Compare your saved starter file with the complete code below.

print("Quiz ready!")

What should the full file contain?

The complete starter file contains one print() call. It displays Quiz ready! when Python runs the file.

Your Python workspace is ready to run code. Next up, you'll replace the starter message with the quiz's first interactive question.

Make One Question Work

Your starter file has already proved that Python can run code on your computer. A quiz becomes interactive when a player's input controls a conditional.

A direct string comparison creates the smallest working question. Testing both letter cases will expose how exact comparisons treat raw text.

In this step, get ready to:
  • Replace the starter message with one multiple-choice question.
  • Store the player's answer in a variable.
  • Test both letter cases against one exact comparison.
Create the first interaction

The input() function pauses the program at a prompt. The answer variable keeps the player's text available for the condition below.

The quiz_game.py file currently contains the starter message from the previous step.

  • Select the print("Quiz ready!") line in quiz_game.py.
  • Replace the selected line with the code below:
print("Which keyword creates a function?")
print("A) func")
print("B) def")
print("C) create")

answer = input("Your answer: ")

if answer == "b":
    print("Correct!")
else:
    print("Not quite.")

What Does This Code Do?

  • The first four print() calls show the question plus its three choices.
  • The input() call displays Your answer: before storing the returned string in answer.
  • The if condition checks whether answer equals lowercase "b".
  • The else branch handles every other string.
  • Four spaces place each result message inside its branch.
  • Save quiz_game.py.

Before you run it, which branch do you think lowercase b will select?

  • Select the Run Python File play button in the top-right corner.
  • Enter b at the Your answer: prompt.

You'll see Correct! below your answer. That is your first interactive quiz branch working.

Quiz Not Reaching the Prompt?

  • If you still see Quiz ready!, save quiz_game.py before running it again.
  • If the terminal never reaches Your answer:, compare your quotes plus indentation with the full code below.

Help me find why my quiz does not reach the answer prompt.

✔️ Awesome, I've got everything!

Your lowercase answer path works. The same file is ready for the second test.

ⓧ I'd like to double check the full code

Compare your saved quiz_game.py file with this complete version.

print("Which keyword creates a function?")
print("A) func")
print("B) def")
print("C) create")

answer = input("Your answer: ")

if answer == "b":
    print("Correct!")
else:
    print("Not quite.")

How the Full File Works

  • The question plus its options appear before input() pauses for the player.
  • The if and else branches select one result from the exact string stored in answer.
Experience the limitation

String equality compares characters exactly. This second run tests whether changing only the letter's case changes the selected branch.

Before you run it again, do you think uppercase B will follow the same branch as lowercase b?

  • Select the Run Python File play button in the top-right corner.
  • Enter B at the Your answer: prompt.

You'll see Not quite. This intended shortfall shows that lowercase "b" differs from uppercase "B" in the current comparison.

You now have a one-question quiz with a visible input edge case. Next, you'll make the quiz handle different letter cases plus surrounding spaces.

Accept and Validate User Input

The one-question Python quiz now checks a player's response. Uppercase B exposed the weakness in exact string comparison.

This step normalizes every answer before comparison. Input validation uses a while loop to keep asking until the player enters A, B, or C.

In this step, get ready to:
  • Normalize each answer before comparison.
  • Define the accepted answer choices.
  • Repeat the prompt until the player enters a valid choice.
Normalize the answer

The input() function captures the player's response as typed. Normalizing that response gives equivalent answers one consistent form.

  • Return to quiz_game.py in Visual Studio Code.
  • Find this line:
answer = input("Your answer: ")

What Does This Line Capture?

This line stores every character exactly as the player enters it. An uppercase B stays uppercase.

  • Replace the current line with this normalized version:
answer = input("Your answer: ").strip().lower()

How Does Normalization Work?

  • .strip() removes whitespace from both ends of the response.
  • .lower() returns a lowercase copy of the response.
  • The normalized result stays in answer for the comparison below.
  • Save quiz_game.py.

Before you test the change, predict whether spaces or capital letters can still alter the result:

  • Select the Run Python File play button.
  • Enter B at the prompt.

You'll see Correct!. The normalized answer now matches lowercase b.

Padded Answer Still Fails?

  • Confirm the input line ends with .strip().lower().
  • Check that the comparison still uses lowercase "b".

Ask for help: Help me debug why padded uppercase input still fails in my Python quiz.

Define valid choices

A Python list stores every accepted answer in one place. A membership check lets the loop detect any response outside that collection.

  • In quiz_game.py, find the normalized answer line.
  • Replace that line with this validation block:
valid_answers = ["a", "b", "c"]
answer = input("Your answer: ").strip().lower()

while answer not in valid_answers:
    print("Please enter A, B, or C.")
    answer = input("Your answer: ").strip().lower()

What Does This Validation Do?

  • valid_answers holds the three responses that the quiz accepts.
  • answer not in valid_answers detects a response outside the list.
  • The while block prints guidance before requesting another answer.
  • The repeated input() call applies the same normalization to every retry.
  • Save quiz_game.py.
Test invalid input

The completed loop controls when the quiz reaches the if check. Its behavior now depends on whether the normalized answer belongs to the valid list.

Before you run both checks, predict how the quiz will handle a padded uppercase answer plus an invalid letter:

  • Select the Run Python File play button.
  • Enter B at the prompt.

You'll see Correct!.

  • Select the Run Python File play button again.
  • Enter x at the prompt.

You'll see Please enter A, B, or C. The quiz waits for another response.

  • Enter b at the new prompt.

You'll see Correct! This proves the quiz rejects invalid input before checking a valid answer.

Invalid Answer Reaches the Result?

  • Place the while block above the if block.
  • Indent both lines inside the while block with four spaces.
  • Check that the condition uses answer not in valid_answers.

Ask for help: Help me find why my quiz accepts invalid input instead of asking again.

✔️ Awesome, I've got everything!

Your file now contains normalization, accepted choices, and a retry loop.

ⓧ I'd like to double check the full code

  • Compare quiz_game.py with this complete version.
print("Which keyword creates a function?")
print("A) func")
print("B) def")
print("C) create")

valid_answers = ["a", "b", "c"]
answer = input("Your answer: ").strip().lower()

while answer not in valid_answers:
    print("Please enter A, B, or C.")
    answer = input("Your answer: ").strip().lower()

if answer == "b":
    print("Correct!")
else:
    print("Not quite.")

How Does the Full Flow Work?

The quiz prints one question before collecting a normalized answer. The validation loop keeps control until the answer belongs to valid_answers.

Once the input is valid, the if block checks whether it matches the correct choice.

That's the fragile input fixed. Next, you'll turn this reliable interaction into a complete quiz.

Turn One Question Into a Quiz

Your one-question Python program now accepts padded answers. It also rejects invalid input. Copying the same variables for every new question would make the file difficult to maintain.

A list of dictionaries gives every question the same structure. A for loop can then process that structure one question at a time.

In this step, get ready to:
  • Store three questions as structured quiz data.
  • Loop through every question in order.
  • Report a score based only on correct answers.
Model each question

Each question needs a prompt. It also needs a set of options. A dictionary groups those related values under consistent keys.

  • Click inside the editor for quiz_game.py.
  • Press Ctrl+A to select the existing code.
  • Replace the selected code with the structured question data below:
QUESTIONS = [
    {
        "prompt": "Which symbol starts a comment in Python?",
        "options": ["A) //", "B) #", "C) <!--"],
        "answer": "b",
    },
    {
        "prompt": "Which keyword creates a function?",
        "options": ["A) def", "B) func", "C) create"],
        "answer": "a",
    },
    {
        "prompt": "Which type stores key-value pairs?",
        "options": ["A) list", "B) string", "C) dictionary"],
        "answer": "c",
    },
]

What Does This Code Do?

  • The QUESTIONS list stores all three quiz questions in one place.
  • The prompt key stores the question shown to the player.
  • The options key stores the three available choices.
  • The answer key stores the lowercase letter used to check the player's response.
  • Save quiz_game.py.
  • Select the Run Python File play button.

The terminal returns without a traceback. This confirms that the three dictionaries use valid Python syntax.

Seeing a Syntax Problem?

  • Check that every question starts with an opening brace. Confirm that it ends with a closing brace.
  • Check that commas separate the dictionary entries. Confirm that the final square bracket closes QUESTIONS.

Ask for help: Help me find the syntax problem in my QUESTIONS list.

Loop through the quiz data

The outer loop handles one question per pass. A nested loop handles each option inside the current question.

  • Place your cursor on a new line below the closing square bracket in quiz_game.py.
  • Add the quiz loop by pasting this code:
VALID_ANSWERS = ["a", "b", "c"]

for question in QUESTIONS:
    print(question["prompt"])

    for option in question["options"]:
        print(option)

    answer = input("Your answer: ").strip().lower()

    while answer not in VALID_ANSWERS:
        print("Please enter A, B, or C.")
        answer = input("Your answer: ").strip().lower()

    if answer == question["answer"]:
        print("Correct!\n")
    else:
        print("Not quite.\n")

How Do the Loops Work?

  • The outer loop reads the dictionaries in QUESTIONS in order.
  • The expression question["prompt"] retrieves the current question text.
  • The inner loop prints every item from question["options"].
  • The validation loop keeps asking until answer contains one of the letters in VALID_ANSWERS.
  • Save quiz_game.py.
  • Select the Run Python File play button.
  • Enter b for the first question.
  • Enter a for the second question.
  • Enter c for the third question.

You'll see all three questions in order. Each question shows its three options before accepting an answer.

You'll see Correct! after each answer. Your single interaction now works across an entire quiz.

Only Seeing One Question?

  • Check that the answer prompt sits inside the outer for loop with four spaces of indentation.
  • Check that the option loop sits inside the question loop. Its print(option) line needs eight spaces of indentation.

Ask for help: Help me fix the indentation in my nested quiz loops.

Track correct answers

The quiz can now check every response. A score turns those individual checks into one result that the player can review.

  • Find the line VALID_ANSWERS = ["a", "b", "c"] in quiz_game.py.
  • Select from that line through the final print("Not quite.\n") line.
  • Replace the selected block with the scoring logic below:
VALID_ANSWERS = ["a", "b", "c"]

score = 0

for question in QUESTIONS:
    print(question["prompt"])

    for option in question["options"]:
        print(option)

    answer = input("Your answer: ").strip().lower()

    while answer not in VALID_ANSWERS:
        print("Please enter A, B, or C.")
        answer = input("Your answer: ").strip().lower()

    if answer == question["answer"]:
        print("Correct!\n")
        score += 1
    else:
        print("Not quite.\n")

print(f"You scored {score}/{len(QUESTIONS)}.")

How Does Scoring Work?

  • The score variable starts at 0 before the question loop begins.
  • The statement score += 1 runs only when the player's answer matches the stored answer.
  • The len(QUESTIONS) expression counts the total number of question dictionaries.
  • The final f-string inserts the score values into one result message.

Before you run the quiz, what final score do you expect from two correct answers plus one incorrect answer?

  • Save quiz_game.py.
  • Select the Run Python File play button.
  • Enter b for the first question.
  • Enter b for the second question.
  • Enter c for the third question.

You'll see Correct! for the first question. You'll see Not quite. for the second question.

The third answer is correct. The final line reads You scored 2/3.

That is the scaling leap complete. Your quiz now processes structured questions in order while counting only correct answers.

Score Not Updating Correctly?

  • Check that score = 0 appears before the outer loop. Placing it inside the loop resets the score for every question.
  • Check that score += 1 sits inside the correct-answer branch with eight spaces of indentation.
  • Check that the final score line has no indentation. This lets it run after every question is complete.

Ask for help: Help me debug why my quiz score is incorrect.

✔️ Awesome, I've got everything!

Your three-question quiz is saved. It displays every question in order while tracking correct answers.

ⓧ I'd like to double check the full code

Compare your complete quiz_game.py file with this version.

QUESTIONS = [
    {
        "prompt": "Which symbol starts a comment in Python?",
        "options": ["A) //", "B) #", "C) <!--"],
        "answer": "b",
    },
    {
        "prompt": "Which keyword creates a function?",
        "options": ["A) def", "B) func", "C) create"],
        "answer": "a",
    },
    {
        "prompt": "Which type stores key-value pairs?",
        "options": ["A) list", "B) string", "C) dictionary"],
        "answer": "c",
    },
]

VALID_ANSWERS = ["a", "b", "c"]

score = 0

for question in QUESTIONS:
    print(question["prompt"])

    for option in question["options"]:
        print(option)

    answer = input("Your answer: ").strip().lower()

    while answer not in VALID_ANSWERS:
        print("Please enter A, B, or C.")
        answer = input("Your answer: ").strip().lower()

    if answer == question["answer"]:
        print("Correct!\n")
        score += 1
    else:
        print("Not quite.\n")

print(f"You scored {score}/{len(QUESTIONS)}.")

What Should Match?

Your file should contain three question dictionaries. It should end with the unindented final score line.

Your quiz now scales through structured data. Next, you'll organize its responsibilities into functions before adding a percentage and tailored feedback.

Organize the Quiz With Functions

Your Python quiz now asks three questions from structured data. It validates each answer before updating the score.

The quiz currently puts every responsibility in one top-level block. Functions separate those jobs into reusable pieces.

In this step, get ready to:
  • Extract the question logic into a reusable function.
  • Build a controller that resets the score for each quiz.
  • Format the score as a percentage with tailored feedback.
Extract the question logic

Each question follows the same sequence of displaying choices, validating input, and checking the answer. The ask_question() function packages that sequence behind one reusable name.

  • Insert the following function below VALID_ANSWERS in quiz_game.py:
def ask_question(question):
    print(question["prompt"])

    for option in question["options"]:
        print(option)

    answer = input("Your answer: ").strip().lower()

    while answer not in VALID_ANSWERS:
        print("Please enter A, B, or C.")
        answer = input("Your answer: ").strip().lower()

    if answer == question["answer"]:
        print("Correct!\n")
        return 1

    correct_answer = question["answer"].upper()
    print(f"Not quite. The correct answer is {correct_answer}.\n")
    return 0

What does this function do?

  • The question parameter holds one dictionary from QUESTIONS.
  • The inner for loop displays every choice stored in that dictionary.
  • The while loop keeps asking until the player enters a valid choice.
  • The function returns 1 for a correct answer. It returns 0 for an incorrect answer.
  • Keep the existing score = 0 line above the question loop.
  • Delete the indented body inside the existing for question in QUESTIONS: loop.
  • Add this line as the loop's new body:
    score += ask_question(question)

How does the score change?

The function returns one point or zero points for each question. The += operator adds that returned value to score.

  • Keep the existing final score print below the question loop.
  • Save quiz_game.py.

Before you run the quiz, consider how many points three correct answers should return.

  • Select Run Python File using the play button in the editor's top-right corner.
  • Enter b for the first question.
  • Enter a for the second question.
  • Enter c for the third question.

You will see Correct! after each answer. The final line will show You scored 3/3..

Quiz stops before the score?

  • Check that every line inside ask_question() uses four spaces for each indentation level.
  • Check that score += ask_question(question) sits inside the outer question loop.
  • Confirm that both return statements are inside ask_question().

Ask for help with my ask_question() function.

Build the quiz controller

The question function handles one question at a time. The run_quiz() controller owns one complete game.

  • Insert the following function below ask_question() in quiz_game.py:
def run_quiz():
    print("Welcome to the Python Syntax Quiz!\n")
    score = 0

    for question in QUESTIONS:
        score += ask_question(question)

    show_result(score, len(QUESTIONS))

What does the controller do?

  • The welcome message marks the start of one quiz attempt.
  • The local score variable starts each attempt at 0.
  • The outer loop passes each dictionary to ask_question().
  • The final call passes the completed score to show_result().
  • Keep the current top-level score block below run_quiz() for this check.
  • Save quiz_game.py.
  • Select Run Python File using the play button in the editor's top-right corner.
  • Complete the three questions.

You will still see all three questions followed by the existing score line. Reaching that score confirms Python accepted the new controller definition.

Quiz no longer starts?

  • Check that the existing top-level score = 0 block remains below run_quiz() for this check.
  • Check that def run_quiz(): begins at the left edge of the file.
  • Check that the controller body uses four spaces of indentation.

Ask for help with my run_quiz() function.

Format the final result

A raw score shows how many questions were correct. A percentage gives that score context while conditional feedback reacts to the player's result.

  • Insert the following function between ask_question() and run_quiz() in quiz_game.py:
def show_result(score, total):
    percentage = score / total * 100
    print(f"You scored {score}/{total} ({percentage:.0f}%).")

    if percentage == 100:
        print("Perfect score! Your Python syntax is taking shape.")
    elif percentage >= 60:
        print("Nice work! Review the question you missed and try again.")
    else:
        print("Good first attempt. Run the quiz again and keep practicing.")

How is the result formatted?

  • The percentage calculation converts the score into a value out of 100.
  • The .0f format displays the percentage with no decimal places.
  • The if branch handles a perfect result.
  • The elif branch handles a result of at least 60 percent.
  • The else branch handles every lower result.
  • Find the final top-level score print below the question loop.
  • Replace that print with this function call:
show_result(score, len(QUESTIONS))

Why pass two values?

The score argument provides the earned points. The len(QUESTIONS) argument provides the total number of questions.

  • Save quiz_game.py.

Before you run this version, consider which rounded percentage two correct answers should produce.

  • Select Run Python File using the play button in the editor's top-right corner.
  • Enter b for the first question.
  • Enter b for the second question.
  • Enter c for the third question.

You will see You scored 2/3 (67%). The next line will show Nice work! Review the question you missed and try again..

Percentage looks wrong?

  • Check that the calculation reads score / total * 100.
  • Check that the percentage placeholder ends with :.0f.
  • Confirm that show_result() receives score as its first argument.

Ask for help with my score percentage.

The result formatter now works. The final change hands control of the entire game to run_quiz().

  • Delete the top-level block that starts with score = 0 and ends with show_result(score, len(QUESTIONS)).
  • Call the controller by adding this line at the bottom of quiz_game.py:
run_quiz()

What starts the quiz?

Defining a function stores its instructions under a name. The final run_quiz() call executes the controller.

  • Save quiz_game.py.

Before you run the finished file, consider the score and percentage that three correct answers should produce.

  • Select Run Python File using the play button in the editor's top-right corner.
  • Enter b for the first question.
  • Enter a for the second question.
  • Enter c for the third question.

You will first see Welcome to the Python Syntax Quiz! After the third answer, you will see You scored 3/3 (100%)..

You did it. Your quiz now ends with Perfect score! Your Python syntax is taking shape. after a perfect result.

Quiz runs twice or misses the welcome message?

  • Confirm that only one run_quiz() call appears at the bottom of the file.
  • Confirm that the old top-level score = 0 block has been removed.
  • Check that the welcome message remains inside run_quiz().

Ask for help with my completed quiz flow.

✔️ Awesome, I've got everything!

Your function-based quiz is complete. Double check that you saved quiz_game.py.

ⓧ I'd like to double check the full code

Compare your complete quiz_game.py file with this version.

QUESTIONS = [
    {
        "prompt": "Which symbol starts a comment in Python?",
        "options": ["A) //", "B) #", "C) <!--"],
        "answer": "b",
    },
    {
        "prompt": "Which keyword creates a function?",
        "options": ["A) def", "B) func", "C) create"],
        "answer": "a",
    },
    {
        "prompt": "Which type stores key-value pairs?",
        "options": ["A) list", "B) string", "C) dictionary"],
        "answer": "c",
    },
]

VALID_ANSWERS = ["a", "b", "c"]


def ask_question(question):
    print(question["prompt"])

    for option in question["options"]:
        print(option)

    answer = input("Your answer: ").strip().lower()

    while answer not in VALID_ANSWERS:
        print("Please enter A, B, or C.")
        answer = input("Your answer: ").strip().lower()

    if answer == question["answer"]:
        print("Correct!\n")
        return 1

    correct_answer = question["answer"].upper()
    print(f"Not quite. The correct answer is {correct_answer}.\n")
    return 0


def show_result(score, total):
    percentage = score / total * 100
    print(f"You scored {score}/{total} ({percentage:.0f}%).")

    if percentage == 100:
        print("Perfect score! Your Python syntax is taking shape.")
    elif percentage >= 60:
        print("Nice work! Review the question you missed and try again.")
    else:
        print("Good first attempt. Run the quiz again and keep practicing.")


def run_quiz():
    print("Welcome to the Python Syntax Quiz!\n")
    score = 0

    for question in QUESTIONS:
        score += ask_question(question)

    show_result(score, len(QUESTIONS))


run_quiz()

Secret mission

Add a Replay Loop

Your quiz currently closes after one game. Add a validated replay prompt that starts a fresh game when the player enters Y. The quiz exits with a closing message when the player enters N.

Clean Up Your Resources

Clean Up Your Resources

Choose whether to keep your quiz ready, pause it for later, or remove its local files. This project runs entirely on your Windows computer, so leaving it in place creates no ongoing costs.

Resources you used:

  • Local python-quiz folder containing quiz_game.py.

Keep everything running

No action is needed. Choose this option if you want to keep testing the quiz or changing its questions.

  • Keep quiz_game.py inside the python-quiz folder.
  • Leave Python 3.14.7 installed for future programs.
  • Leave Visual Studio Code installed for future projects.
  • Keep the Python extension for Visual Studio Code enabled for running Python files.

Pause - I'll come back to this later

Pause any active quiz run to free the terminal session. Keep the project files ready for your next coding session.

  • Enter n at the replay prompt if the quiz is currently running.

You'll see Thanks for playing! when the quiz ends.

  • Save quiz_game.py.
  • Close Visual Studio Code.

Your python-quiz folder remains on your computer with the completed game inside.

Delete - I don't want to use this again

Remove the local quiz files if you want to start fresh. Your installed programming tools remain available for other projects.

Permanent deletion can feel final. Keep a copy of quiz_game.py somewhere else first if you may want to revisit your work.

  • Enter n at the replay prompt if the quiz is currently running.
  • Close Visual Studio Code.
  • Use Windows search to open your computer's file browser.
  • Use the search field to find python-quiz.

You'll see the local folder that contains quiz_game.py.

  • Move python-quiz to the recycle area.
  • Open the recycle area with Windows search.
  • Select python-quiz.

Windows may ask you to confirm the permanent deletion. Confirming removes the folder and its quiz file from your computer.

  • Permanently delete the selected python-quiz folder.
  • Confirm the deletion if Windows asks.
  • Use Windows search to look for python-quiz again.

You should no longer see python-quiz in the results. That's your local cleanup complete.

Nice Work!

Nice Work!

Mission complete! You built a replayable terminal quiz in Python that responds reliably to every player.

You've learned how to:

  • Built an interactive quiz that gives immediate feedback. Added input validation that accepts uppercase or lowercase answers with surrounding spaces.
  • Stored every question in a list of dictionaries. Used for loops to process the questions in order.
  • Built reusable functions with parameters plus return values. Used those values to calculate a score and percentage before showing tailored feedback.
  • Secret Mission: Added a validated replay loop that starts a fresh quiz when the player enters y. Entering n closes the game with Thanks for playing!.

Ready to quiz yourself?