In my last post, I showed off a program I wrote using Python to make a Mad Libs game. If you have been deprived of the hilarity that is Mad Libs (i.e. if you don't know what it is), check out my previous post about it or this wikipedia entry. Or you can just keep on reading because you'll probably figure it out just by reading this post. :-)
I promised in my last post that I would show you how to create your own Mad Libs game using Python, so read on...
Step One: Create!
The first step is to create your own Mad Libs story. You can make up a story on your own or use song lyrics, a nursery rhyme, or a poem.
In your story, to go along with the Mad Libs format, be sure to include blank spaces for the missing words and decide what part of speech (noun, pronoun, adjective, verb, etc.) belongs in each blank. Here is an example using the nursery rhyme "Humpty Dumpty":
(Person's name) Dumpty (verb in the past tense) on a wall.
(Person's name) Dumpty had a/n (adjective) fall.
All the king's (plural animal) and all the (profession)'s men
Couldn't put (Person's name) together again.
For this example, we have five variables: a person's name, a verb in the past tense, an adjective, a plural animal, and a profession. Yes, I am using the math term "variable" here, but that's only because it'll make it easier to understand when we start working in Python.
Step Two: Trinket!
Now that you've created your story (If you haven't, then STOP NOW and go back and write a story, lazybutt!), it's time to start writing your program.
In order to write your program, you have to have a place to write it, right? You can download a platform for Python (which I don't know anything about, sorry) or you can create an account at trinket.io. So go do that now.
Now that you have your new trinket account, create a new trinket using python. I'm not going to tell you how to do that. You're smart; I'm sure you can figure it out.
The new trinket you create looks like this:
You will write your program on the left side of the screen, and then when you click the "Run" button at the top, the output of your program is shown on the right side.
Step Three: Variables!
To convert your story into a usable program, first you have to set up your fill-in-the-blank items for the user (the person running your program and responding to it). To do that, use this format:
variable_name = raw_input ("The content you want the user to respond to.")
The words written in purple are the words that you will change. The rest of it is Python formatting that you have to maintain. Here is an example I would use from my "Humpty Dumpty" story:
persons_name = raw_input ("Give the name of a person.")
There are a few things you need to know when you're setting up your questions. First, your variable name (the thing that comes before the equal sign) cannot be separated by a space, so if I tried using this--persons name--it wouldn't work. Instead of using a space, using an underscore if you absolutely have to have two words.
In addition, you have to give each of your variables a different name. Say for instance that in your story, you are asking for three different nouns. Each of those nouns needs a different variable name in order for your program to work smoothly. To make things easy, you can just call them noun1, noun2, and noun3. For instance:
noun1 = raw_input("Name a noun.")
noun2 = raw_input("Name another noun.")
noun3 = raw_input("Name yet another noun.")
One more thing: the punctuation you use has to exactly match the format I've shown you. If you forget to close your parentheses or forget the quotation marks, your program will not work properly. Make absolutely sure that your punctuation is correct.
Before we go on to the next part of your program, try running the program you have so far. If you've typed everything correctly, then the program will prompt you to answer each question. Go ahead. Answer each question and see what happens.
Step Three: Story!
After you answered each question, not much happened, did it? That's because we haven't put the answers into the story yet. Let's do that now.
The next thing you want to do is write your story and tell the program to grab the user's answers to your questions to replace the blanks in your story. Here is the format for that:
print "This is your story right here. %s The percent signs represent the blanks in your %s story. They are replaced by the variables within the %s parentheses that follow the stuff in quotation marks." % (variable_name1, variable_name2, variable_name3)
Again, the words in purple are the parts you will change based on the needs of your story. The items in black have to look exactly like that so that Python will understand what to do. So for my Humpty Dumpty story, this is what I would write:
print "%s Dumpty %s on a wall. %s Dumpty had a/n %s fall. All the king's %s and all the %s's men couldn't put %s together again." % (persons_name, verb, persons_name, adjective, animal, profession, persons_name)
Step Four: Addendum!
Note that I used the person's name multiple times, so I just repeated it several times in my variable list in the parentheses so that the program would know where to put it in the story.
Also, you may have noticed that your story kept going on and on and extending way across the page. If you want to prevent that from happening, you can tell Python that you want to continue your text on the next line. To do that, insert a backslash (\) and hit Enter on the keyboard wherever you want to break to the next line, like this:
print "This story is getting really long. I mean, it's getting so long that it is bleeding across the page. Arrgh! \
Okay, I put in a backslash so that it wouldn't be so long because, man, it was getting really long, wasn't \
One more thing--if your output on the right side of the screen is too squished together--in other words, if you want to put in blank lines--just add the word "print" in the places where you want a blank line.
For example, I write this:
noun = raw_input("Name a noun.")
adjective = raw_input("Name an adjective.")
verb = raw_input("Name a verb.")
And it looks like this in the output (the right-hand) screen:
Name a noun.
Name an adjective.
Name a verb.
It doesn't look like this:
Name a noun.
Name an adjective.
Name a verb.
Step Five: Share!
After you've finished and trouble-shooted (trouble-shot?) your work, show it to all your friends (and enemies), post it to Facebook, tweet about it, and share it everywhere. Also, please put a link to it in the comments, and I'll look at it as well. And finally, if you have any questions, I'll try to answer them. Just leave them in the comments below. Thanks!
And if you liked these instructions, please share them. Tweet or share this post on Facebook by clicking the buttons below. Thank you!!!!!!
For the last few posts, I've basically been sharing ideas that I wish someone had shared with me when I was young. But here's the thing, you're not a one-dimensional person--like a Flat Stanley or a line--and neither am I. I have muchos intereses and muchas actividades that take up my awake-time, and I'm sure you do too. So I want to introduce you to a current one.
Meet Logical Me
I've been teaching a short 6-week computer class to Upward Bound students. The thing is though that I don't have a degree in computer science. Actually, I don't have any training in computer science, and frankly, I'm not that interested in computer science either. I mean, I can use a computer, but "networking" is a foreign word to me and if you asked me to hack something, I'd get out a butcher knife.
I Have a Big "But"
BUT I am "teaching" a computer class this summer anyway. :-) Luckily, as a former librarian and a non-idiot, I am resourceful enough to find teaching materials online, so my students and I are using Codecademy to learn to code using the Python computer language.
I don't know anything about computer programming, mind you (maybe I mentioned my computer illiteracy before?), and huge portion of what I'm "learning" in Codecademy doesn't make a darn bit of sense to me right now. But I have managed to make a simple game using Python.
Presenting "A Mad, Mad, Mad, Mad, Mad Libs World"!
Okay, so maybe you're not familiar with Mad Libs. It was pretty popular back when I was growing up in the Pleistocene epoch (alongside mammoths and saber-toothed tigers). Here's how it works: you create a story (or use a pre-made template) with several words missing. You have to figure out what part of speech (noun, adjective, adverb, etc.) would make sense in each of the blanks. Then, you ask people to give you a word that goes with those parts of speech. Finally, you use their answers to fill in the blanks, and you read their new, hilarious story.
An Example to Un-confuse You
Here's how I would make "Mary Had a Little Lamb" into a Mad Libs:
Me: Name an adjective.
Me: Name an animal.
Me: Name a body part.
Me: Name an adjective.
Here's your Mad Libs version of "Mary Had a Little Lamb":
Mary had a fun chimpanzee.
Its earlobe was stripey as snow...
Hahahaha! And everyone rolls in the floor with laughter and/or bewilderment!
A Link To Mad(Lib)ness
Here is the Mad Libs game I created. To start it, click the word Run with the little triangle next to it. Then, type in an answer to each question and hit "Enter" on your keyboard. Finally, read your ["Give me an adjective." "bizarre" "Give me another adjective." "slimy"] story that you created (i.e. Then, read, your bizarre, slimy story that you created).
Now It's Time to Say Goodbye...
So I'm out of time for now, kiddos! But in my next post, I will show you how to create your own Mad, Mad, Mad, Mad, Mad Libs World so you can join the novice-geek squad. Until then, seeya, sucka!
If thou dost liketh this posteth, pleaseth to share-eth it witheth thine friendeth by clickingeth one of the buttons beloweth. Thanketh thee!
Word and Book Lover.