Module 9 โ Build Simple AI Projects! ๐ ๏ธ
intermediate25 XP
Guessing Game & Story Machine! ๐๐ฎ
Build a funny AI fortune teller and a random story generator in Python
Guessing Game & Story Machine! ๐๐ฎ
Project 1: The AI Fortune Teller ๐ฎ
A magic 8-ball that uses AI-style responses!
Python
import random
def fortune_teller(question):
responses = [
# Positive
"๐ The AI predicts: DEFINITELY YES! The stars align in your favour!",
"โ
My circuits say: Almost certainly! Go for it!",
"๐ The probability matrix says: Yes, and it'll be AMAZING!",
"๐ My neural networks are 94.7% certain: YES!",
# Uncertain
"๐ค Hmm... My algorithms are confused. Try asking clearer?",
"โ๏ธ The data is mixed. Could go either way, honestly.",
"๐ My prediction: It's uncertain. The future is hard to compute!",
# Negative
"๐ฌ The AI hesitates... Maybe wait a bit?",
"โ My calculations suggest: Not the best idea right now!",
"๐ System says: Try again later. Current conditions unfavourable.",
]
print(f"\n๐ค Analysing your question...")
print(f"Processing 1,000,000 data points... ๐ญ")
print(f"\n{random.choice(responses)}\n")
# Run it!
print("๐ฎ Welcome to the AI Fortune Teller 3000!")
print("Ask me ANY yes/no question...\n")
while True:
question = input("Your question: ")
if question.lower() in ["quit", "bye", "exit"]:
print("๐ค Goodbye! May your future be full of bugs... I mean, features! ๐")
break
fortune_teller(question)Project 2: The Random Story Generator ๐
Python
import random
def generate_story():
characters = ["a confused robot", "a sleepy wizard", "a pizza-loving cat",
"a time-travelling student", "a dancing gorilla"]
locations = ["inside a video game", "on the moon", "in a Minecraft world",
"at a sushi restaurant", "in a school for superheroes"]
problems = ["forgot how to do maths", "accidentally became famous on TikTok",
"their pet started speaking Python", "fell asleep in a Zoom call",
"ate 47 chicken nuggets and gained flying powers"]
solutions = ["by asking Cody the AI for help", "by writing a Python program",
"by blaming their WiFi", "by explaining it was 'an AI glitch'",
"by finding a cheat code in real life"]
character = random.choice(characters)
location = random.choice(locations)
problem = problems[random.randint(0, len(problems)-1)]
solution = random.choice(solutions)
story = f"""
๐ ONCE UPON A TIME...
There was {character} who lived {location}.
One day, they {problem}.
"Oh no!" they cried. "This is catastrophic!"
But after much thinking (and 3 cups of hot chocolate โ),
they solved the problem {solution}.
And they all lived happily ever after. THE END. ๐
"""
return story
# Generate stories!
print("๐ The Random Story Generator 3000!")
while True:
input("Press ENTER for a new story (or Ctrl+C to quit)...")
print(generate_story())๐ก What These Projects Teach
These silly projects use real AI concepts:
- Random selection = how AI generates varied responses
- Template + variable filling = how AI language models work
- Response libraries = like AI training data
- User input loops = how chatbots work
ChatGPT is essentially a much, much more sophisticated version of these ideas!
โจ๏ธ
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
The fortune teller program uses random.choice() โ what does this do?