Skip to content Cajun Code Monkey Logo
Cajun
Code
Monkey

Game dev course, lesson 1: a Mad Lib console game

Posted on:April 14, 2026 at 02:00 PM

Table of Contents

Open Table of Contents

Before you start 🧭

✅ If you are new to computers or using code editors, you may want someone with a little more experience nearby to help you with the steps in this lesson.

✅ Typing and using the editor may feel slow at first. This is completely normal! You will get faster with practice.

✅ If you haven’t already, complete lesson 0 first to verify your setup and get familiar with the editor and terminal.

✅ Full install guide (editor, uv, Python, Hello World, files): companion SETUP.md.

✅ Stuck? All code examples and solutions are in the companion lab repository.

🎯 Pro tip: you learn faster when you type the code yourself instead of copy-pasting. Short lines beat big paste blocks!

Goals 🎯

By the end of this lesson you will:

Why a Mad Lib is “game dev” ✨

A Mad Lib is a tiny story machine (grown-ups might say “narrative engine”): the computer knows the shape of a story, and you supply the missing pieces. Bigger games fill in slots too—hero names, item labels, win messages—using variables and text just like you will here.

Mini project: dungeon contract 🏰

You will collect silly words, then print a one-paragraph “contract” for an adventurer.

Step 1 — a file and a first print 🪄

Create madlib.py in your lesson folder. Type:

print("Welcome, apprentice scribe!")

Run the file. If it prints the message, your workshop is wired up correctly. ✅

What does print do? (click or tap to open)

print is a built-in Python command that tells the computer to show text in the terminal—the window where lines of text scroll by.

The parentheses ( … ) wrap what you want to show. The quotes ” … ” mean say these letters exactly (a string of characters). So print(“Welcome, apprentice scribe!”) draws that welcome line on screen.

Later, you will print variables too, not only fixed phrases.

Step 2 — variables hold player answers 📦

Variables are named boxes for values.

hero_name = "Alex"
print(hero_name)

Here the box is named hero_name and holds the text "Alex".

In Step 3, you will reuse the same name hero_name—first we practiced with a test value, then we swap in what the player types.

Step 3 — ask the player with input() 💬

input() pauses and waits for the player to type a line and press Enter.

hero_name = input("Name your hero: ")
print(hero_name)

The text the player types becomes the value stored in hero_name.

What does input do? (click or tap to open)

input is a built-in Python command that asks the human a question in the terminal, then waits while they type an answer and press Enter.

The text inside the parentheses—usually in quotes—is the prompt: the line the player sees before they type. So input(“Name your hero: ”) shows Name your hero: and the cursor blinks after it.

Whatever they typed on that line (before Enter) becomes a string value you can store in a variable with =, like hero_name = input(…).

Step 4 — build a story with an f-string ✍️

An f-string lets you slip variables into a larger string.

hero_name = input("Name your hero: ")
creature = input("Name a ridiculous creature: ")
tool = input("Name a useless adventuring tool: ")

story = f"""
{hero_name} signed a contract to hunt a {creature},
armed only with a {tool}.
Good luck, {hero_name}.
"""

print(story)

Run it, answer the prompts, and read the contract aloud if you dare. 🎲

You already used an f-string for the contract. Next is the big picture on regular strings and f-strings—same ideas, with tiny examples you can run in a scratch file.

Strings and f-strings 📚

A string is a sequence of characters: letters, digits, spaces, punctuation, emoji, or escape codes like \n for a new line.

You can wrap text in double quotes or single quotes for simple strings—this lesson mostly uses doubles.

Triple quotes """ … """ let you write several lines in one string. That is how your contract can span more than one line.

An f-string adds the letter f right before the opening quotes, for example f""" … """. Inside the string, curly braces around a variable name are slots: Python swaps in the current value when that line runs.

Each line below prints the same greeting so you can compare styles:

print("Hello, World!")
print(f"Hello, World!")
name = "World"
print(f"Hello, {name}!")

Concatenation means joining strings with +:

print("Hello, " + "World!")

For many slots (like hero_name, creature, and tool in your story), f-strings stay the easiest to read.

💡 Hint

If you see a NameError for hero_name, make sure you assigned hero_name = input(...) above the story block.

Try this 🛠️

  1. Add two more prompts (for example: a location and a magic word) and weave them into the same story.
  2. Greet the player using their hero name in the very first line printed.
  3. Blank lines: experiment with extra \n inside the f-string to space the story for readability.

Stretch goals 🌟

  1. Non-empty answers: if the player hits Enter without typing, ask again until you get at least one character.

    🙈 Spoiler direction Ask a grown-up to read this with you if you want to try it early.

    Use a while loop and len(...) — you will see loops formally in a later lesson, so this is optional adventuring.

  2. Second paragraph: print a second f-string that references the same variables so the contract feels longer.

Recap 📝

Next lesson (preview) 🔮

Next you will build a guess the number game: logic, branching (if / elif / else), and while loops so the computer can react to each guess until the player wins. 🎯