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?