Build a Mad Libs Game in Python – Interactive Tutorial

Build a Mad Libs Game in Python – Interactive Tutorial

Build a Mad Libs Game in Python

Welcome back to DarchumsTech! Today, you’re going to build a fun little word game called Mad Libs. You’ll ask the player to fill in some blanks, and then you’ll plug those words into a wacky story.


🧠 What You’ll Learn

  • How to take user input
  • Using strings and string formatting
  • Writing a basic game loop

🛠️ Step 1: Create a Story Template

We’ll make a story with blanks for the user to fill in. Here's how:

print("Welcome to the Mad Libs Game!")

noun = input("Enter a noun: ")

adjective = input("Enter an adjective: ")

verb = input("Enter a verb: ")

place = input("Enter a place: ")

print("\nHere is your story:\n")

print(f"Once upon a time in {place}, there was a {adjective} {noun} who loved to {verb} all day.")

💡 How It Works

This code asks the player to enter a few words. Then it uses an f-string to insert those words into a short story!

🎮 Sample Output

Welcome to the Mad Libs Game!

Enter a noun: dragon

Enter an adjective: happy

Enter a verb: dance

Enter a place: castle

Here is your story:

Once upon a time in castle, there was a happy dragon who loved to dance all day.

🔄 Step 2: Make It Replayable

Let’s add a loop to play the game multiple times:

while True:

    noun = input("Enter a noun: ")

    adjective = input("Enter an adjective: ")

    verb = input("Enter a verb: ")

    place = input("Enter a place: ")

    print(f"\nOnce upon a time in {place}, there was a {adjective} {noun} who loved to {verb} all day.\n")

    again = input("Play again? (yes/no): ")

    if again.lower() != "yes":

        break

✅ Final Notes

  • Get creative! Add more blanks and make longer stories.
  • Try using a dictionary to store the inputs.
  • Add emojis or color (using a library like colorama).

📬 Stay Tuned!

This was a fun project, but we’ve got more coming! Next up: Rock, Paper, Scissors in Python.

Subscribe to DarchumsTech for more beginner-friendly Python projects.

Comments