1 00:00:00,560 --> 00:00:03,650 So far, what we have done is all output. 2 00:00:03,650 --> 00:00:06,489 We printed the screen, it's not very interactive, is it? 3 00:00:06,489 --> 00:00:08,100 The conversation's kind of one sided. 4 00:00:09,260 --> 00:00:12,895 Take a second and think about applications that you use. 5 00:00:12,895 --> 00:00:16,425 Just about every one of them gathers information from you, whether that be 6 00:00:16,425 --> 00:00:21,785 a field, or a check box, a button click, or telling a bird when to flap its wings. 7 00:00:21,785 --> 00:00:25,640 Every application you make is going to need to gather some information from its 8 00:00:25,640 --> 00:00:27,647 users, this is called input. 9 00:00:28,677 --> 00:00:32,397 And gathering input from users from the command line is pretty straight forward, 10 00:00:32,397 --> 00:00:33,787 so let's get to it. 11 00:00:33,787 --> 00:00:37,347 So let's explore this input thing a little bit in the Python shell first. 12 00:00:37,347 --> 00:00:40,307 So I'm gonna open that up, we'll type python. 13 00:00:42,140 --> 00:00:44,830 Let's give ourselves a little bit of space. 14 00:00:44,830 --> 00:00:50,684 All right, so the command to get input from the user is super easy to remember, 15 00:00:50,684 --> 00:00:51,757 it's input. 16 00:00:51,757 --> 00:00:55,550 So input, that's a function, so we're gonna call it. 17 00:00:56,620 --> 00:00:58,960 And inside here you put the prompt. 18 00:00:58,960 --> 00:01:03,930 So let's ask a question, so let's say, How are you today? 19 00:01:05,450 --> 00:01:09,545 So see how the cursor is here, it's waiting for me to type, so how am I? 20 00:01:09,545 --> 00:01:14,200 Great, I mean you're standing a little close to me, but pretty great. 21 00:01:14,200 --> 00:01:17,050 Already we're seeing the importance of user experience right? 22 00:01:17,050 --> 00:01:19,890 That prompt made me feel uncomfortable. 23 00:01:19,890 --> 00:01:21,270 So I'm gonna press Enter. 24 00:01:21,270 --> 00:01:24,670 And now, remember, in the REPL we see the results show up. 25 00:01:24,670 --> 00:01:29,830 So what happens is when you call the input function, it outputs out the prompt and 26 00:01:29,830 --> 00:01:31,865 then it waits for an answer. 27 00:01:31,865 --> 00:01:34,285 Once the answer to the prompt is given, and 28 00:01:34,285 --> 00:01:38,465 the user presses Enter, the result is returned. 29 00:01:38,465 --> 00:01:41,925 So we know that this input returns a string, so 30 00:01:41,925 --> 00:01:43,785 let's capture it in a new variable. 31 00:01:43,785 --> 00:01:47,412 So let's see, what would how are you today be? 32 00:01:47,412 --> 00:01:52,420 [SOUND] I guess that'd probably be something like current mood, right? 33 00:01:52,420 --> 00:01:54,360 [LAUGH] Naming things is hard, isn't it? 34 00:01:54,360 --> 00:01:55,130 So we do current, 35 00:01:55,130 --> 00:01:57,570 and then we're gonna use the underscore, cuz there's two words, right? 36 00:01:57,570 --> 00:02:00,856 So current_mood, that's current mood in snake case. 37 00:02:00,856 --> 00:02:06,700 And we'll say, again, we do the input, How are you today? 38 00:02:06,700 --> 00:02:11,610 Now, you know what, I'm gonna use couple of spaces just to give some room there for 39 00:02:11,610 --> 00:02:13,090 user experience. 40 00:02:13,090 --> 00:02:13,940 So let's do this. 41 00:02:13,940 --> 00:02:16,536 So how are you today? 42 00:02:16,536 --> 00:02:19,884 Well, I am wonderful, especially [LAUGH] now that you're not standing so 43 00:02:19,884 --> 00:02:20,480 close to me. 44 00:02:21,860 --> 00:02:25,520 And now our variable, current_mode, if we just type that out here, 45 00:02:25,520 --> 00:02:27,280 we can see what's in it, wonderful. 46 00:02:28,472 --> 00:02:31,810 Awesome, so you know what, we could just put this in our program. 47 00:02:31,810 --> 00:02:35,800 We could ask for the user's first name, so let's do it. 48 00:02:35,800 --> 00:02:39,120 So we'll just replace this value with the input statement. 49 00:02:40,220 --> 00:02:43,444 We'll say, what is your first name? 50 00:02:43,444 --> 00:02:45,418 And then we'll definitely give them some space, 51 00:02:45,418 --> 00:02:47,930 cuz we want them to feel comfortable, awesome. 52 00:02:47,930 --> 00:02:51,080 So now, you know what else, let's scroll this down, 53 00:02:51,080 --> 00:02:54,390 let's get rid of these other lines in here where we're saying hello. 54 00:02:54,390 --> 00:02:58,003 So I'm gonna Cmd+Shift+D that and Cmd+Shift+D this, 55 00:02:58,003 --> 00:03:00,260 and let's bring this back up. 56 00:03:00,260 --> 00:03:01,820 There we go, that's looking good. 57 00:03:01,820 --> 00:03:05,420 And it's saved, so let's go ahead, I'm gonna drop out of the shell, Ctrl+D. 58 00:03:05,420 --> 00:03:11,630 I'm gonna clear the console, and I'm gonna type python hello.py. 59 00:03:11,630 --> 00:03:12,660 So what is your first name? 60 00:03:14,030 --> 00:03:16,800 I just got an email from one of my students, so he's on my mind right now. 61 00:03:16,800 --> 00:03:19,890 So I'll enter Kehinde. 62 00:03:23,966 --> 00:03:27,110 Hello, Kehinde, Kehinde is learning Python. 63 00:03:27,110 --> 00:03:29,120 How's the weather in Nigeria this time of year, Kehinde? 64 00:03:30,494 --> 00:03:35,247 And so you'll see that the first name variable is now set to 65 00:03:35,247 --> 00:03:37,940 whatever we enter from input. 66 00:03:37,940 --> 00:03:42,130 So the program changes based on our user's input, which is awesome. 67 00:03:42,130 --> 00:03:47,090 Because now we're dealing with input and output, the staples of application 68 00:03:47,090 --> 00:03:48,300 development, great job. 69 00:03:49,540 --> 00:03:54,100 We stumbled right into a fundamental problem that you're gonna encounter daily 70 00:03:54,100 --> 00:03:57,730 in your coding journey, naming things is hard. 71 00:03:57,730 --> 00:04:00,650 Now you'll get better at it, [LAUGH] but it's never easy. 72 00:04:00,650 --> 00:04:05,532 And I can't stress this enough, a good name is really important. 73 00:04:05,532 --> 00:04:10,322 You wanna be able to look at your code and understand and remember what it's doing. 74 00:04:10,322 --> 00:04:12,460 You wanna be able to read it next week. 75 00:04:12,460 --> 00:04:16,070 Now one thing to remember, and most people who are just getting started coding 76 00:04:16,070 --> 00:04:21,250 don't think about this too often, other people are going to read your code. 77 00:04:21,250 --> 00:04:25,550 Now, that might seem like a totally foreign idea, but ready for this? 78 00:04:25,550 --> 00:04:28,420 You're going to be most likely on a team, and 79 00:04:28,420 --> 00:04:31,440 your teammates will need to understand what you are trying to communicate. 80 00:04:32,610 --> 00:04:34,960 We already know that the computer has rules for 81 00:04:34,960 --> 00:04:37,280 understanding what we're talking about, right? 82 00:04:37,280 --> 00:04:38,580 That's called syntax. 83 00:04:38,580 --> 00:04:40,700 But what we're talking about here is coding style. 84 00:04:40,700 --> 00:04:44,888 [SOUND] There is absolutely nothing stopping you from using a single letter 85 00:04:44,888 --> 00:04:48,007 variable name for the current mood code that we wrote. 86 00:04:48,007 --> 00:04:51,770 Like I could store the result from the prompt, how are you today, 87 00:04:51,770 --> 00:04:53,150 in a variable called m. 88 00:04:54,280 --> 00:04:58,750 But, I can guarantee that your actual real life mood is going to change for 89 00:04:58,750 --> 00:05:00,340 the worst, when you read this code and 90 00:05:00,340 --> 00:05:03,670 have to try to figure out, what does m mean? 91 00:05:03,670 --> 00:05:08,790 Great news though, the Python community as a whole are very big on consistent style. 92 00:05:08,790 --> 00:05:11,390 Chances are after you learn the style rules, 93 00:05:11,390 --> 00:05:16,270 your code will be indistinguishable from that of a long time Python coder. 94 00:05:16,270 --> 00:05:19,650 I'll point these standard style decisions out as we encounter them. 95 00:05:19,650 --> 00:05:23,930 The one we've seen already is use snake_case for variable names. 96 00:05:23,930 --> 00:05:27,930 Now it's definitely not a syntax error, you could use another casing system, 97 00:05:27,930 --> 00:05:30,300 like for instance, you could say currentMood. 98 00:05:30,300 --> 00:05:33,695 This is called camel case, each word here has a new hump. 99 00:05:33,695 --> 00:05:38,340 [SOUND] thisIsAnExampleOfWhatCamelCasingLooksLike. 100 00:05:38,340 --> 00:05:42,002 If you're working with a team on a project, you'll wanna make sure that you 101 00:05:42,002 --> 00:05:45,170 follow the same style that is being used in the project. 102 00:05:45,170 --> 00:05:46,970 Try to stay consistent. 103 00:05:46,970 --> 00:05:48,720 So, how are you feeling? 104 00:05:48,720 --> 00:05:50,870 You've picked up quite a bit of information over these 105 00:05:50,870 --> 00:05:52,100 past couple of videos. 106 00:05:52,100 --> 00:05:54,990 I know that it's a lot, especially if this is your first language. 107 00:05:54,990 --> 00:05:57,800 So let me say again, great job sticking with it. 108 00:05:57,800 --> 00:06:00,950 What you've been learning will give you a great foundation to dive deeper and 109 00:06:00,950 --> 00:06:02,350 explore the language. 110 00:06:02,350 --> 00:06:05,970 We've got the starts of what every application has, input and output. 111 00:06:07,040 --> 00:06:10,110 Next up, let's start processing that input that we receive, 112 00:06:10,110 --> 00:06:10,990 right after this quick break.