Locked lesson.
About this lesson
Let's practice our skills with user input to build a Madlib Program!
Exercise files
Download this lesson’s related exercise files.
22 - Build a Madlib Program.docx61.1 KB 22 - Build a Madlib Program SOLUTION.docx
58.8 KB
Quick reference
Build a Madlib Program!
Madlib programs are fun little apps that give you experience getting and using user input.
When to use
These are just for fun!
Instructions
Create a series of questions where the user inputs answers. Then take their answer and output them to the screen in a funny way.
Hints & tips
- Have some fun with it!
- 00:04 Okay, so in this video we're going to build a very basic Mad Lib game.
- 00:07 And if you remember Mad Libs from when you were a kid,
- 00:09 you have to create a list of nouns, verbs, adjectives, all that, and then it kind of
- 00:14 puts them all together into a little story, and they're usually hilarious.
- 00:19 This one probably isn't going to be that hilarious because I'm not that creative.
- 00:22 But at least we can kind of play around with this and
- 00:24 use what we learned in the last video with user input and
- 00:27 output to create a little something, get a little practice with this.
- 00:30 So let's come over here.
- 00:32 And like I said, this is going to be a very, very basic Mad Lib game.
- 00:38 So say we want five things, so let's go one,
- 00:43 two, three, four, five.
- 00:46 So here let's say enter a person's name.
- 00:52 And inside of this one we want to say enter a verb,
- 00:58 enter a place, enter a size, I don't know,
- 01:03 and let's say enter a color, right.
- 01:09 So beneath each of these we want to get some user input.
- 01:11 So let's go console.read line.
- 01:16 And remember we need to set these equal to something.
- 01:18 So let's come up here and let's create some variables.
- 01:22 These are all going to be strings.
- 01:24 Let's just create a list, and
- 01:25 we can do these all on one line if they're all the same thing.
- 01:28 So here name, let's say verb,
- 01:33 place, size, and color, right.
- 01:39 So here we could say Name = And
- 01:46 let me just kind of paste all these in, That.
- 01:52 So here we need to change name to verb,
- 01:56 this to place, this to size, and this to color.
- 02:02 Okay, finally we need to output our story.
- 02:08 So let's say output story.
- 02:11 And let's create some interpolation to make this easier.
- 02:16 So let's go name, verb,
- 02:21 base, place, space,
- 02:25 size, space, and color.
- 02:30 Now how do we want to do this?
- 02:33 Let's say name verb to the place, and
- 02:37 ordered a size, and I don't know, taco.
- 02:43 So not a very interesting Mad Lib but it's something.
- 02:48 So let's go ahead and save this, let's run it.
- 02:53 So enter a person's name, John, enter a verb, ran,
- 02:58 and our place, I don't know, garage,
- 03:02 enter a size, large, and our color, red.
- 03:06 John ran to the garage and ordered a large red taco.
- 03:09 Hilarious, like I said, I'm not very creative, but
- 03:13 play around with this, make your own Mad Lib.
- 03:17 This is a very basic example but
- 03:19 you can see just that easy to initialize all of our variables.
- 03:24 Get user's input, save those things to variables, and
- 03:28 then do something weird with all of those variables.
- 03:31 So that's all for this video.
- 03:32 In the next video we're going to jump into more intermediate topics,
- 03:35 we're going to look at arrays.
Lesson notes are only available for subscribers.