1 00:00:00,660 --> 00:00:03,980 To put all of your knowledge together, we're going to create a Mad Lib. 2 00:00:05,030 --> 00:00:08,280 A Mad Lib is a fun activity where you ask someone for 3 00:00:08,280 --> 00:00:13,250 nouns, verbs, adjectives, etc, and then use them in a silly paragraph. 4 00:00:17,849 --> 00:00:19,970 We will be working in a new workspace. 5 00:00:19,970 --> 00:00:21,058 So go ahead and 6 00:00:21,058 --> 00:00:26,418 launch the latest workspace with this video if you haven't already. 7 00:00:26,418 --> 00:00:29,262 Click on the madlib.py file to open it, 8 00:00:29,262 --> 00:00:33,370 if it isn't open already, and let's look at our Mad Lib. 9 00:00:35,310 --> 00:00:37,490 These are called comments. 10 00:00:37,490 --> 00:00:42,280 They don't run when the file is run in the console, they're just information for us. 11 00:00:43,390 --> 00:00:48,131 Each bracket is where we'll need to ask the user for something, an adjective, and 12 00:00:48,131 --> 00:00:50,890 then print it out in the sentence. 13 00:00:50,890 --> 00:00:54,000 Let's create all of the variables and inputs first. 14 00:00:55,010 --> 00:00:57,522 I'm going to use the name of the item and 15 00:00:57,522 --> 00:01:01,590 then a number to represent its place in the paragraph. 16 00:01:01,590 --> 00:01:08,167 For instance, the first one will be called adjective1. 17 00:01:08,167 --> 00:01:12,982 Then plural_noun2, 18 00:01:12,982 --> 00:01:17,560 and so on and so forth. 19 00:01:17,560 --> 00:01:21,181 adjective1 = 20 00:01:21,181 --> 00:01:28,424 input('Adjective: '). 21 00:01:28,424 --> 00:01:33,490 plural_noun = input 22 00:01:33,490 --> 00:01:39,360 ('Plural Noun: '). 23 00:01:39,360 --> 00:01:44,547 verb3 = input 24 00:01:44,547 --> 00:01:50,933 ('Verb: '). 25 00:01:50,933 --> 00:01:58,339 verb4 = input ('Verb: '). 26 00:01:58,339 --> 00:02:02,613 adjective5 = input 27 00:02:02,613 --> 00:02:07,602 ('Adjective: '). 28 00:02:07,602 --> 00:02:15,170 Make sure I got them all. 29 00:02:15,170 --> 00:02:19,486 Adjective, plural noun, verb, verb, adjective. 30 00:02:19,486 --> 00:02:22,290 Next is family member. 31 00:02:28,523 --> 00:02:34,790 Family_member6 = input ('Family Member: '). 32 00:02:37,980 --> 00:02:42,208 Need another verb7 = 33 00:02:42,208 --> 00:02:46,883 input('Verb: '). 34 00:02:46,883 --> 00:02:52,685 Then we need a plural_noun8 35 00:02:52,685 --> 00:02:59,422 = input ('Plural Noun: '). 36 00:02:59,422 --> 00:03:04,789 And finally, we need one more 37 00:03:04,789 --> 00:03:09,942 adjective, adjective9 = 38 00:03:09,942 --> 00:03:15,533 input('Adjective: '). 39 00:03:18,898 --> 00:03:21,090 Awesome. 40 00:03:21,090 --> 00:03:23,310 We've got all of our inputs written. 41 00:03:23,310 --> 00:03:25,970 Let's save and run the file. 42 00:03:30,840 --> 00:03:34,160 This way we can make sure we don't have any spelling errors. 43 00:03:55,280 --> 00:04:01,430 Great, next we need to use the input to print out our Mad Lib. 44 00:04:01,430 --> 00:04:06,198 Let's print out each sentence line by line, 45 00:04:06,198 --> 00:04:10,970 so we can make sure to use the right variable. 46 00:04:10,970 --> 00:04:14,214 Create a little bit of space, print and 47 00:04:14,214 --> 00:04:20,128 we know we're gonna have to use our string formatting, so f(' '). 48 00:04:20,128 --> 00:04:25,577 And we can copy and paste our first sentence here, 49 00:04:25,577 --> 00:04:29,985 Ctrl + C or Command + C, and then Ctrl or 50 00:04:29,985 --> 00:04:33,507 Command + V to paste it in here. 51 00:04:33,507 --> 00:04:38,684 Then we turn our square brackets into 52 00:04:38,684 --> 00:04:44,370 curly brackets and add our number, 1. 53 00:04:46,620 --> 00:04:50,221 And let's repeat that for 54 00:04:50,221 --> 00:04:55,948 all of our sentences print(f' ''), 55 00:04:55,948 --> 00:05:00,858 copy sentence two, copy, paste, 56 00:05:00,858 --> 00:05:04,950 and don't forget we'll need 57 00:05:04,950 --> 00:05:10,200 an underscore here, this will be 2. 58 00:05:11,800 --> 00:05:13,750 And we'll need to do the same thing with this verb. 59 00:05:15,300 --> 00:05:18,913 It could be 3 and 60 00:05:18,913 --> 00:05:24,250 then print(f' '). 61 00:05:24,250 --> 00:05:26,810 Let's get our next sentence. 62 00:05:35,960 --> 00:05:39,030 Change these to curly brackets. 63 00:05:39,030 --> 00:05:45,224 We're on 4, So 64 00:05:45,224 --> 00:05:50,096 adjective is 5, curly bracket. 65 00:05:50,096 --> 00:05:55,537 Repeat again, print(f' '), 66 00:05:55,537 --> 00:06:00,980 grab our second to last sentence, 67 00:06:00,980 --> 00:06:07,172 paste, curly bracket, underscore, 68 00:06:07,172 --> 00:06:12,238 the number 6, curly bracket, 69 00:06:12,238 --> 00:06:18,242 curly bracket, 7, curly bracket, 70 00:06:18,242 --> 00:06:24,059 curly bracket, underscore, 8 and 71 00:06:24,059 --> 00:06:29,720 curly bracket and we have one more. 72 00:06:33,905 --> 00:06:36,169 Print(f' ') 73 00:06:39,854 --> 00:06:43,998 Copy and paste, 74 00:06:43,998 --> 00:06:49,622 curly, 9, curly and 75 00:06:49,622 --> 00:06:54,960 save, run the file. 76 00:07:04,405 --> 00:07:12,890 Enter whatever you want. 77 00:07:24,732 --> 00:07:31,548 Oops, says our family_member6 78 00:07:31,548 --> 00:07:34,840 is not defined. 79 00:07:36,030 --> 00:07:36,760 Let's see why. 80 00:07:38,010 --> 00:07:38,970 Oops, l spelled it wrong. 81 00:07:38,970 --> 00:07:40,300 l have family memeber. 82 00:07:41,560 --> 00:07:46,198 So remove that, and then make sure it's also spelled correctly down here, 83 00:07:46,198 --> 00:07:48,079 family_member6, okay. 84 00:07:48,079 --> 00:07:48,579 Save. 85 00:07:56,290 --> 00:08:02,207 Let's run 86 00:08:02,207 --> 00:08:09,440 that again. 87 00:08:17,170 --> 00:08:19,040 And there's your Mad Lib. 88 00:08:19,040 --> 00:08:24,250 Nice work, you have a working Mad Lib program, pat yourself on the back. 89 00:08:25,320 --> 00:08:29,688 Feel free to grab a friend, roommate or significant other and 90 00:08:29,688 --> 00:08:35,370 have them input the adjectives and nouns and run their own Mad Lib. 91 00:08:35,370 --> 00:08:39,930 As a challenge, I've placed another Mad Lib and the second file here. 92 00:08:41,880 --> 00:08:46,630 Go ahead and try creating this Mad Lib program on your own. 93 00:08:46,630 --> 00:08:48,890 Pause me and I'll see you back here in a bit. 94 00:08:50,700 --> 00:08:53,360 All right, let me walk you through what I did. 95 00:08:53,360 --> 00:08:58,170 First, I created all of the variables and inputs like this one. 96 00:09:02,230 --> 00:09:08,607 Then I created the print statements with string formatting using curly brackets and 97 00:09:08,607 --> 00:09:12,870 the variable names to input our user's information. 98 00:09:12,870 --> 00:09:16,700 Save and run the file. 99 00:09:21,448 --> 00:09:29,626 Make sure 100 00:09:29,626 --> 00:09:34,737 to put 101 00:09:34,737 --> 00:09:44,737 madlib2. 102 00:09:53,369 --> 00:09:58,170 I like to have cats, plants, 103 00:09:58,170 --> 00:10:03,665 and dogs on my desk at all times. 104 00:10:03,665 --> 00:10:06,080 This helps me stay focused when I eat. 105 00:10:06,080 --> 00:10:11,520 I also keep my bug close to keep cars from bothering me while I catch. 106 00:10:11,520 --> 00:10:14,370 When I'm running, I use the Doug Technique. 107 00:10:14,370 --> 00:10:18,350 It's where you spend 30 minutes gaming and then 2 minutes sleeping. 108 00:10:18,350 --> 00:10:20,930 This makes me a wonderful worker. 109 00:10:20,930 --> 00:10:22,825 I wish I could spend 30 minutes gaming and 110 00:10:22,825 --> 00:10:26,250 then 2 minutes sleeping to complete my work every day. 111 00:10:26,250 --> 00:10:29,867 Take some time and look at all of the code you've written so far. 112 00:10:36,010 --> 00:10:40,650 You are on your way to becoming a great Pythonista. 113 00:10:42,440 --> 00:10:47,912 So far, you've learned how to create a variable that holds a string, 114 00:10:47,912 --> 00:10:53,568 how to print out strings and variables to the console, how to run a file, 115 00:10:53,568 --> 00:10:59,720 how to ask for input and save the result in a variable and how to format strings. 116 00:11:01,230 --> 00:11:03,290 That's a ton of knowledge already. 117 00:11:03,290 --> 00:11:04,080 You're amazing.