Skip to content

Instantly share code, notes, and snippets.

@mcburton
Last active August 26, 2025 15:51
Show Gist options
  • Select an option

  • Save mcburton/7570a1344f95b7d9faece0b40038c0e3 to your computer and use it in GitHub Desktop.

Select an option

Save mcburton/7570a1344f95b7d9faece0b40038c0e3 to your computer and use it in GitHub Desktop.
import marimo
__generated_with = "0.14.17"
app = marimo.App(width="medium", auto_download=["html"])
@app.cell
def _():
# Python Mad Libs
# The code in this project has three sections:
# THE STORY
# The mad libs story with placeholders for the user's input using Python format strings.
# PROMPTING THE USER
# Prompt the user with the input function for each placeholder
# GENERATE THE STORY FROM THE DATA
# Display the completed mad libs story by filling the placeholders with the user's input
# Welcome to the Mad Libs game! Print a blank line and an introduction
print()
print("Answer the following prompts for words. These words will then be used to populate a story. ")
## THE STORY
# The mad libs story with placeholders for the user's input using Python format strings.
story = """Once upon a time, in a {place1}, there lived a {adjective1} {noun1} who was known for their {adjective2} ability to {verb1}. Every morning, the {noun1} would stroll through the {adjective3} village, greeting everyone with a {adjective4} smile. One sunny day, while {verb2} near the {adjective5} river, a {adjective6} {noun2} appeared, holding a mysterious, shimmering {noun3}. “This {noun3} will {verb3} your deepest {noun4},” it whispered. Intrigued, the {noun1} accepted the gift and suddenly found themselves {verb4} on an unexpected adventure.\n\nTheir journey led them to a {adjective7} forest, where they encountered a {adjective8} {noun5} in distress. The {noun5} explained that a {adjective9} {noun6} had taken their precious {noun7}, and they needed help to {verb5} it back. Bravely, the {noun1} agreed to assist, and together they embarked on a perilous quest.\n\nFinally, after a {adjective10} encounter with the {adjective11} {noun6}, they retrieved the lost {noun7}, discovering the true power of {noun8} and {noun9}. The {noun1} returned home, forever changed by their {adjective12} journey, and the {place1} celebrated their {adjective13} tale for generations.
"""
## PROMPTING THE USER
# Prompt the user with the input fuction for each placeholder
place1 = input("Enter a place: ")
adjective1 = input("Enter an adjective: ")
noun1 = input("Enter a type of person: ")
adjective2 = input("Enter an adjective: ")
verb1 = input("Enter a verb: ")
adjective3 = input("Enter an adjective: ")
adjective4 = input("Enter an adjective: ")
verb2 = input("Enter an -ing verb: ")
adjective5 = input("Enter an adjective: ")
adjective6 = input("Enter an adjective: ")
noun2 = input("Enter a type of animal: ")
noun3 = input("Enter a type of object: ")
verb3 = input("Enter an -ing verb: ")
noun4 = input("Enter an emotion: ")
verb4 = input("Enter a -ing verb: ")
adjective7 = input("Enter an adjective: ")
adjective8 = input("Enter an adjective: ")
noun5 = input("Enter another type of animal: ")
adjective9 = input("Enter an adjective: ")
noun6 = input("Enter another type of person: ")
noun7 = input("Enter another type of object: ")
verb5 = input("Enter a verb: ")
adjective10 = input("Enter an adjective: ")
adjective11 = input("Enter an adjective: ")
noun8 = input("Enter an abstract noun: ")
noun9 = input("Enter another abstract noun: ")
adjective12 = input("Enter an adjective: ")
adjective13 = input("Enter an adjective: ")
## GENERATE THE STORY FROM THE DATA
# print a blank line
print()
# add a little delay for dramatic effect
print("Generating Story...")
from time import sleep
sleep(1)
print()
# Display the completed mad libs story by fillin the placeholders with the user's input
print(story.format(**locals()))
return
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment