Kids Coding
Project: Mad Libs
Ask for words, then fill a silly story. print, input, and strings together.
Fill a silly story
Mad Libs asks for words, then drops them into a story. You already have print, strings, and variables. That is the whole project.
The pieces
- Pick a name, a place, and a food.
- Join them into sentences.
- Print the story.
A story (saved words)
name = "Sam"
place = "the moon"
food = "noodles"
print("Once, " + name + " went to " + place + ".")
print(name + " packed a lunch of " + food + ".")
print("It was a very strange day.")On a computer, replace each saved word with input("A name: ") and friends can type their own.
Make it yours
Change the sentences. Add a fourth word. Print a title line first.
Real life
Making up a lunch-table story with friends.
Each friend drops in a word. The story changes. That is Mad Libs at the cafeteria.
Cafeteria story
friend = "Jun"
food = "noodles"
place = "the roof"
print(friend + " ate " + food)
print("then ran to " + place + ".")
print("The teacher was not happy.")Change one word. Run it. That is how this idea shows up outside the lesson.
Try it
Exercise 1: Write a three-line story that uses animal and colour.
Show solution
animal = "fox"
colour = "teal"
print("A " + colour + " " + animal + " sat down.")
print("It wanted a snack.")
print("Then it ran home.")