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?