Module 9 – Build Simple AI Projects! 🛠️
intermediate25 XP

Build an AI Quiz Bot! 🎯

Create a Python quiz game with score tracking, hints, and encouraging messages

Build an AI Quiz Bot! 🎯

Your Quest: Build a Smart Quiz Game!

We'll build a quiz bot that:

  • ✅ Asks multiple-choice questions
  • ✅ Tracks your score
  • ✅ Gives hints when you're wrong
  • ✅ Gives encouraging AI-style messages!

Step 1: The Question Database

Python
# Our quiz questions — stored as a list of dictionaries!
questions = [
    {
        "question": "What does AI stand for?",
        "options": ["A) Automatic Instructions", "B) Artificial Intelligence", 
                    "C) Amazing Internet", "D) Auto Input"],
        "answer": "B",
        "hint": "Think: fake (artificial) thinking (intelligence)!"
    },
    {
        "question": "Which app uses AI to recommend videos you'll love?",
        "options": ["A) Calculator", "B) Notes", "C) TikTok", "D) Clock"],
        "answer": "C",
        "hint": "It's that app where you lose track of time! 📱"
    },
    {
        "question": "What is training data used for in AI?",
        "options": ["A) Making AI run faster", "B) Paying AI developers", 
                    "C) Teaching AI by showing it examples", "D) Decorating computers"],
        "answer": "C",
        "hint": "It's how AI learns — like showing a baby pictures!"
    },
]

Step 2: The Quiz Engine

Python
import random

def run_quiz(questions):
    score = 0
    # Shuffle so it's different each time!
    random.shuffle(questions)
    
    print("🤖 Welcome to AI QuizBot 3000!")
    print("=" * 40)
    
    for i, q in enumerate(questions, 1):
        print(f"\nQuestion {i}: {q['question']}")
        for option in q['options']:
            print(f"  {option}")
        
        answer = input("\nYour answer (A/B/C/D): ").upper()
        
        if answer == q['answer']:
            score += 1
            print("✅ CORRECT! Amazing! 🎉")
        else:
            print(f"❌ Not quite! Hint: {q['hint']}")
            print(f"The answer was {q['answer']}!")
    
    return score

# Run it!
final_score = run_quiz(questions)
total = len(questions)
percentage = (final_score / total) * 100

print(f"\n🏆 Final Score: {final_score}/{total} ({percentage:.0f}%)")

if percentage == 100:
    print("PERFECT SCORE! You're an AI genius! 🤖👑")
elif percentage >= 70:
    print("Great work! You really know your AI! 🌟")
elif percentage >= 50:
    print("Not bad! Keep studying and try again! 📚")
else:
    print("Keep learning! You'll get there! 💪")

🏆 Challenges: Make It Even Better!

  1. Add more questions about AI topics you've learned
  2. Add difficulty levels: easy/medium/hard
  3. Add a high score tracker that saves to a file
  4. Add a timer: 10 seconds per question!
  5. Add categories: Python questions vs AI questions

💡 What Makes This "AI-Inspired"?

The quiz uses:

  • Data structures (dictionaries) — just like AI knowledge bases
  • Random shuffling — like how AI varies recommendations
  • Score tracking — like AI measuring accuracy
  • Feedback loops — like how AI learns from mistakes

Building this teaches you the foundations of how real AI systems work!

⌨️

Type it yourself

Don't just read it — type the example from above into the box, press Run ▶, and watch what happens. Typing it yourself is how it really sticks! Stuck? Tap Show example.

Python · Playground
Output
Press ▶ Run to see your code come to life…

Quick check

01/2

In the quiz code, what does random.shuffle(questions) do?