Quiz Game in Python This is a beginner-friendly Python project where users can test their general knowledge through a multiple-choice quiz game. The program presents questions, collects user input, checks the answers, and displays the final score. It also includes a simple scoring system and feedback after each question. The quiz questions are stored in a dictionary, making it easy to expand the game with more questions or categories. This project is perfect for learning basic concepts like loops, conditionals, functions, and user input handling.

Quiz Game in Python

image

This beginner-friendly Python project is a fun way to test your general knowledge with a simple multiple-choice quiz game. The program asks a series of questions, lets you choose your answers, and gives you instant feedback along with your final score.

All the questions are neatly organized in a dictionary, so it’s super easy to add more or even create different quiz categories. It’s a great little project to help you practice key programming concepts like loops, conditionals, functions, and working with user input.

Whether you’re just starting out with Python or looking for a fun side project, this quiz game is a great way to build your skills while having a bit of fun!

πŸ’‘ Features:

  • User-friendly interface with emojis and clean formatting.

  • Robust input validation.

  • Feedback after each question (correct/incorrect).

  • Personalized greeting and score summary.

  • Modular and readable structure with well-named functions.

				
					import time


# -----------------------------
# Quiz data
# -----------------------------
quiz_questions = [
    {
        "question": "What is the capital of France?",
        "options": ["A) Paris", "B) London", "C) Rome", "D) Berlin"],
        "answer": "A"
    },
    {
        "question": "Which planet is known as the Red Planet?",
        "options": ["A) Earth", "B) Mars", "C) Venus", "D) Jupiter"],
        "answer": "B"
    },
    {
        "question": "Who wrote 'Hamlet'?",
        "options": ["A) Charles Dickens", "B) William Wordsworth", "C) William Shakespeare", "D) Jane Austen"],
        "answer": "C"
    },
    {
        "question": "Which language is primarily used for web development?",
        "options": ["A) Python", "B) Java", "C) HTML", "D) C++"],
        "answer": "C"
    },
    {
        "question": "What is the boiling point of water?",
        "options": ["A) 100Β°C", "B) 90Β°C", "C) 120Β°C", "D) 80Β°C"],
        "answer": "A"
    }
]

# -----------------------------
# Utility Functions
# -----------------------------
def welcome_user():
    print("🌟 Welcome to the Simple Quiz Game! 🌟")
    name = input("Enter your name: ")
    print(f"\nHello, {name}! Let's test your knowledge.\n")
    time.sleep(1)
    return name

def ask_question(q, index):
    print(f"Question {index + 1}: {q['question']}")
    for option in q["options"]:
        print(option)
    answer = input("Your answer (A/B/C/D): ").strip().upper()
    while answer not in ['A', 'B', 'C', 'D']:
        answer = input("Please enter a valid option (A/B/C/D): ").strip().upper()
    return answer == q["answer"]

def show_results(score, total):
    print("\nπŸŽ‰ Quiz Completed! πŸŽ‰")
    print(f"Your Score: {score} out of {total}")
    percentage = (score / total) * 100
    if percentage == 100:
        print("πŸ† Perfect! You're a quiz master!")
    elif percentage >= 70:
        print("πŸ‘ Great job! You really know your stuff.")
    elif percentage >= 50:
        print("πŸ™‚ Not bad, but you can do better.")
    else:
        print("πŸ˜… Keep practicing, you'll get there!")

# -----------------------------
# Execution Program
# -----------------------------
def run_quiz():
    user_name = welcome_user()
    score = 0
    total_questions = len(quiz_questions)

    for i, question in enumerate(quiz_questions):
        print("-" * 50)
        if ask_question(question, i):
            print("βœ… Correct!\n")
            score += 1
        else:
            print(f"❌ Wrong! The correct answer was {question['answer']}.\n")
        time.sleep(1)

    print("-" * 50)
    show_results(score, total_questions)
    print("\nThank you for playing, " + user_name + "! πŸ‘‹")

# Entry
if __name__ == "__main__":
    run_quiz()