Python Mad Libs for Kids

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:

 1from datetime import datetime
 2
 3a = input("Enter a name: ")
 4a1 = input(f"Is {a} a boy or girl: ")
 5a2 = "He" if a1 == "boy" else "She"
 6b = input("Enter an adjective: ")
 7c = input("Enter an animal (including Human): ")
 8d = input("Enter a food: ")
 9e = input("Enter a verb: ")
10f = input("Enter another name: ")
11g = input("Enter a place: ")
12h = input("Enter another name: ")
13i = input("Enter an action (past tense): ")
14j = input("Enter an action (past tense): ")
15k = input("Enter a food: ")
16l = input("Enter an action (past tense): ")
17m = input("Enter a noun: ")
18
19non_particular = "an" if b[0].upper() in ["A", "E", "I", "O", "U"] else "a"
20
21story = f" \
22Once upon a time, there was {non_particular} {b} {c} named {a}. \
23{a} loved to eat {d}. {a2} also liked to {e} \
24with {f}, and watch TV.  \
25\
26One day, {a} went to the {g} and found {h}. They {i} and {j}. \
27They also ate {k} and {l} on the {m}. \
28\
29The End. \
30\
31"
32
33print(story)
34
35save_story = input("Save story? Y/N: ")
36if save_story.upper() == "Y":
37	outF = open(f"""story_{datetime.now().strftime("%Y%m%d_%H%M%S")}.txt""", "w")
38	outF.write(story)
39	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.

Translations: