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
  • βœ… Checks answers and keeps score
  • βœ… Gives hints when you're wrong
  • βœ… Cheers you on at the end!
πŸ’‘

πŸ’‘ On this website, Python can't wait for you to type, so the player's answers come from a list. On your own computer you could use input() instead.

Step 1: The question bank

Each question is a dictionary, and all of them go in a list:

Python
questions = [
    {"question": "What does AI stand for?",
     "options": ["A) Automatic Instructions", "B) Artificial Intelligence", "C) Amazing Internet"],
     "answer": "B",
     "hint": "Think: artificial (made by people) + intelligence (thinking)!"},
    {"question": "What is training data used for?",
     "options": ["A) Making computers faster", "B) Decorating apps", "C) Teaching AI with examples"],
     "answer": "C",
     "hint": "It's how AI learns, like showing a toddler lots of pictures!"},
    {"question": "Which of these uses AI to forecast storms?",
     "options": ["A) A weather app", "B) A light switch", "C) A pencil"],
     "answer": "A",
     "hint": "It looks at tons of past weather data to spot patterns."},
]

player_answers = ["B", "A", "A"]
score = 0

for i in range(len(questions)):
    q = questions[i]
    print("Q" + str(i + 1) + ":", q["question"])
    if player_answers[i] == q["answer"]:
        score = score + 1
        print("  Correct!")
    else:
        print("  Not quite! Hint:", q["hint"])

print("Final score:", score, "out of", len(questions))

Step 2: Cheer the player on πŸŽ‰

Python
score = 2
total = 3
percent = score * 100 // total

if percent == 100:
    print("PERFECT! You're an AI genius!")
elif percent >= 60:
    print("Great work! You really know your AI!")
else:
    print("Keep learning! You'll get there!")

πŸ’‘ What makes this "AI-inspired"?

  • A knowledge bank (a list of dictionaries), like the data AI systems store
  • Checking answers and keeping score, like how AI measures its accuracy
  • Hints when wrong, like the feedback AI uses to improve

πŸ† Challenge ideas

  1. Add more questions about AI topics you've learned.
  2. Add an easy/medium/hard level to each question.
  3. Use random.shuffle(questions) to mix up the order each time!
⌨️

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/4
In the quiz code, what does random.shuffle(questions) do?