How to Create a MCQ Quiz Game in Python: Complete Step-by-Step Guide

How-to-Create-a-MCQ-Quiz-Game-in-Python-Complete-Step-by-Step-Guide
Credit: codingstreets

Overview: MCQ Quiz Game in Python

In this Python tutorial for beginners 2026, you’ll learn how to create a fully functional Multiple Choice Question (MCQ) quiz game in Python. We’ll build an interactive console application that presents questions, validates user input, tracks scores in real-time, and provides immediate feedback for each answer. You’ll master key programming concepts including nested dictionaries for data organization, loops for iterating through questions, conditional logic for answer validation, and score tracking systems.

This article will guide you through creating a complete quiz application with a polished user interface, making it perfect for beginners looking to build their first interactive game or educational tool in Python.

Table of Contents

Pre-requisite for the project

  1. Dictionary: It stores question & answer as key:value pairs.

Key Points to Remember for Logic Building

#1. MCQs questions -> dictionary: key:value pair
#2. iterate over each question with options & answer – for loop
#3. Validate if user’s input is valid – while loop
#4. Check MCQs answers -> conditional statements: if elif… else
#5. Display answers with current score

Complete Code: MCQ Quiz Game in Python: A Complete Tutorial

				
					def mcq_game():
    mcq_questions = {
        1: {
            "question": "What is the capital of France?",
            "options": ["A) London", "B) Berlin", "C) Paris", "D) Madrid"],
            "answer": "C"},
        2: {
            "question": "Which planet is known as the Red Planet?",
            "options": ["A) Venus", "B) Mars", "C) Jupiter", "D) Saturn"],
            "answer": "B"},
        3: {
            "question": "What is 5 + 7?",
            "options": ["A) 10", "B) 11", "C) 12", "D) 13"],
            "answer": "C"},
        4: {
            "question": "Which language is known as the language of the web?",
            "options": ["A) Python", "B) Java", "C) JavaScript", "D) C++"],
            "answer": "C"},
        5: {
            "question": "Who painted the Mona Lisa?",
            "options": ["A) Van Gogh", "B) Picasso", "C) Da Vinci", "D) Rembrandt"],
            "answer": "C"}
    }

    print("🎮 WELCOME TO THE QUIZ GAME! 🎮")
    print("- Answer each question by entering A, B, C, or D")
    print("You'll get 1 point for each correct answer\n")
    
    score = 0
    total_questions = len(mcq_questions)

    #loop all questions
    for question_number, question_data in mcq_questions.items():
        print(f"Question: {question_number}: {question_data['question']}")

        #loop all options
        for option in question_data['options']:
            print(option)

        #get answer
        while True:
            user_answer = input('Your answer: (A/B/C/D): ').upper().strip()

            if user_answer in ['A', 'B', 'C', 'D']:
                break
            else:
                print("❌ Invalid input! Please enter A,B,C, or D")

        #check_answer
        correct_answer = question_data['answer']

        if user_answer == correct_answer:
            print("✅ Correct!")
            score += 1
        else:
            print(f"❌ Wrong Answer!!! Correct answer is: {correct_answer}")
        
        print(f"Current Score: {score}/{question_number}\n")
        
    print("📊 QUIZ COMPLETED!")
    print(f"Final Score: {score}/{total_questions}")

mcq_game()
				
			

Step by Step Code Explanation

Function Definition and Quiz Data Structure

				
					def mcq_game():
    mcq_questions = {
        1: {
            "question": "What is the capital of France?",
            "options": ["A) London", "B) Berlin", "C) Paris", "D) Madrid"],
            "answer": "C"},
        # Additional questions follow the same structure
    }
				
			
  • def mcq_game():: Defines the main function that encapsulates all quiz logic.

  • Nested Dictionary: Uses a multi-level dictionary structure:

    • Outer dictionary keys (1, 2, 3…) represent question numbers

    • Inner dictionaries store question text, options, and correct answer

  • Data Organization: This structure makes it easy to add, remove, or modify questions without changing the game logic.

User Interface and Game Instructions

				
					    print("🎮 WELCOME TO THE QUIZ GAME! 🎮")
    print("- Answer each question by entering A, B, C, or D")
    print("You'll get 1 point for each correct answer\n")
				
			
  • Welcome Banner: Emojis (🎮) create visual appeal and modern interface.
  • Clear Instructions: Explains input format and scoring system upfront.
  • Proper Formatting: Empty lines (\n) improve readability.

Score Initialization and Setup

				
					    score = 0
    total_questions = len(mcq_questions)
				
			
  • Score Tracking: Initializes score variable to zero.

  • Dynamic Countinglen(mcq_questions) automatically calculates total questions, making the game scalable.

Main Quiz Loop

				
					    for question_number, question_data in mcq_questions.items():
        print(f"Question: {question_number}: {question_data['question']}")
				
			
  • Dictionary Iterationmcq_questions.items() loops through all questions.
  • Unpacking: Extracts both question number and question data in each iteration.
  • Question Display: Shows question number and text in a clean format.

Options Display System

				
					        for option in question_data['options']:
            print(option)
				
			
  • Options Loop: Iterates through the list of options for each question.

  • Clean Presentation: Displays each option on a new line automatically.

Input Validation Loop

				
					        while True:
            user_answer = input('Your answer: (A/B/C/D): ').upper().strip()

            if user_answer in ['A', 'B', 'C', 'D']:
                break
            else:
                print("❌ Invalid input! Please enter A,B,C, or D")
				
			
  • Infinite Loopwhile True ensures the user must provide valid input before continuing.

  • Input Cleaning.upper().strip() converts to uppercase and removes extra spaces.

  • conditional statement (if): It checks if user’s input is valid or not. If valid, it breaks the loop.

  • Error Feedback: Emoji (❌) and clear message guide users to correct input.

Answer Checking and Scoring

				
					        correct_answer = question_data['answer']

        if user_answer == correct_answer:
            print("✅ Correct!")
            score += 1
        else:
            print(f"❌ Wrong Answer!!! Correct answer is: {correct_answer}")
        
        print(f"Current Score: {score}/{question_number}\n")
				
			
  • Answer Retrieval: Extracts correct answer from question data.

  • Comparison Logic: Checks if user’s answer matches the correct answer.

  • Immediate Feedback: Uses emojis (✅/❌) for visual feedback.

  • Score Update: Increments score only for correct answers.

  • Progress Tracking: Shows current score after each question.

Game Completion and Results

				
					    print("📊 QUIZ COMPLETED!")
    print(f"Final Score: {score}/{total_questions}")
				
			
  • Completion Message: Clear indication that the quiz has ended.

  • Final Results: Displays final score with total questions for context.

Application Execution

				
					mcq_game()
				
			
  • Function Call: Starts the MCQ quiz game.

Conclusion: MCQ Quiz Game in Python

This MCQ quiz game in Python demonstrates how to create an engaging, interactive application using Python’s fundamental data structures and control flow mechanisms. The important programming concepts: data organization with nested dictionaries, user input handling with validation loops, real-time score tracking, and immediate feedback systems. The modular structure makes it easy to extend and customize for various educational purposes, making it a valuable learning project for Python beginners 2026 and a useful template for creating more complex quiz applications.

Recent Articles