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!
- Add more questions about AI topics you've learned
- Add difficulty levels: easy/medium/hard
- Add a high score tracker that saves to a file
- Add a timer: 10 seconds per question!
- 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?