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 with AI-style answers! random.choice() picks one item from a list, so you get a different answer each time you press Run.

Python
import random

responses = [
    "The AI predicts: DEFINITELY YES!",
    "My circuits say: almost certainly!",
    "Hmm... my algorithms are confused. Ask again?",
    "The data is mixed. Could go either way!",
    "My calculations say: not right now!",
]

questions = ["Will I win my soccer game?", "Will it snow tomorrow?", "Is pizza the best food?"]

for question in questions:
    print("You ask:", question)
    print("Fortune Teller:", random.choice(responses))
    print()
๐Ÿ’ก

๐Ÿง  This isn't real prediction: it's just random! Real AI forecasts (like weather apps) look at data to make a smart guess. That's the big difference.

Project 2: The Story Machine ๐Ÿ“š

AI writing tools fill in templates with words that fit. Let's make a silly version:

Python
import random

characters = ["a confused robot", "a sleepy wizard", "a pizza-loving cat", "a brave honeybee"]
places = ["on the moon", "inside a video game", "at the bottom of the ocean", "on a busy farm"]
problems = ["lost their homework", "accidentally became famous", "started speaking Python"]

for story_number in range(1, 3):
    print("Story", story_number)
    print("Once upon a time,", random.choice(characters), "lived", random.choice(places) + ".")
    print("One day, they", random.choice(problems) + "!")
    print("They fixed it with a little help from AI. THE END.")
    print()

Press Run again and again: new stories every time! ๐ŸŽฒ

๐Ÿ’ก What these projects teach

  • Random choice = how AI tools can give varied answers
  • Templates + fill-in words = a simple version of how AI writes text
  • Word lists = like a (tiny!) set of training data

Tools like ChatGPT are far more advanced, but they also build text piece by piece, choosing words that fit.

โŒจ๏ธ

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
The fortune teller program uses random.choice() โ€” what does this do?