Python Mad Libs for Kids

Published: Aug 20, 2021

Well, I came up with a Python idea that got my 6-year-old daughter pretty hooked. Mad Libs! It’s basically just a series of text prompts that feeds into a story. The f-string in Python was very intuitive for her to learn and she quickly was able to help me troubleshoot. It’s a great way for her to entertain herself by filling in her own story, reading it aloud, and laughing her butt off…

Here’s the script:

from datetime import datetime

a = input("Enter a name: ")
a1 = input(f"Is {a} a boy or girl: ")
a2 = "He" if a1 == "boy" else "She"
b = input("Enter an adjective: ")
c = input("Enter an animal (including Human): ")
d = input("Enter a food: ")
e = input("Enter a verb: ")
f = input("Enter another name: ")
g = input("Enter a place: ")
h = input("Enter another name: ")
i = input("Enter an action (past tense): ")
j = input("Enter an action (past tense): ")
k = input("Enter a food: ")
l = input("Enter an action (past tense): ")
m = input("Enter a noun: ")

non_particular = "an" if b[0].upper() in ["A", "E", "I", "O", "U"] else "a"

story = f" \
Once upon a time, there was {non_particular} {b} {c} named {a}. \
{a} loved to eat {d}. {a2} also liked to {e} \
with {f}, and watch TV. \
\
One day, {a} went to the {g} and found {h}. They {i} and {j}. \
They also ate {k} and {l} on the {m}. \
\
The End. \
\
"

print(story)

save_story = input("Save story? Y/N: ")
if save_story.upper() == "Y":
outF = open(f"""story_{datetime.now().strftime("%Y%m%d_%H%M%S")}.txt""", "w")
outF.write(story)
outF.close()

Here’s an example output:

Once upon a time, there was a cute tigee named Moofy. Moofy loved to eat ice cream. She also liked to fart with Nellie, and watch TV. One day, Moofy went to the the bed and found Daddy. They played piano and burped. They also ate pizza and slept on the remote control. The End.

Previous Post

It's not the energy reeling...

It's not the energy reeling... nor the lines in your face... nor the clouds on the ceiling... nor the clouds in space. It's not the phone on the table... nor the bed in the earth... nor the bed in the stable... nor your stable words. It's not the formless being...

Next Post

Sept 11, 1973... The Real 9/11

Never Forget...