1 00:00:00,300 --> 00:00:01,260 Welcome back. 2 00:00:01,440 --> 00:00:05,860 Let's try and do an exercise to tie everything that we've learned up until now. 3 00:00:05,880 --> 00:00:09,330 Together, we're going to create a password checker. 4 00:00:09,900 --> 00:00:15,840 Now, what we want to do is to create some sort of an input that we're going to ask. 5 00:00:15,840 --> 00:00:22,770 So we're going to use the input function, and here we're going to ask for a username. 6 00:00:23,010 --> 00:00:25,560 Then we're going to ask for another input. 7 00:00:25,860 --> 00:00:28,860 It's going to be the password. 8 00:00:30,330 --> 00:00:35,910 And then at the end with the input we want to print. 9 00:00:36,870 --> 00:00:37,620 Something. 10 00:00:37,620 --> 00:00:40,890 The lines of password. 11 00:00:41,220 --> 00:00:45,630 And then we'll have maybe the actual password in here. 12 00:00:46,050 --> 00:00:51,120 And it will say, is another variable here long. 13 00:00:51,390 --> 00:00:57,330 So what we want to do is the password and then maybe the password. 14 00:00:58,350 --> 00:00:59,070 Length. 15 00:00:59,960 --> 00:01:07,710 So that let's say we printed our username JJ and then we give it a password of secret. 16 00:01:08,060 --> 00:01:11,960 Well, we should print the password. 17 00:01:12,500 --> 00:01:20,570 Secret is one, two, three, four, five, six letters long. 18 00:01:21,680 --> 00:01:30,260 Now, obviously, we don't want to show or display the password, maybe for security reasons. 19 00:01:30,260 --> 00:01:36,440 So we want to convert this secret to one, two, three, four, five, six, two stars. 20 00:01:37,500 --> 00:01:42,960 So your task is to convert these two inputs. 21 00:01:43,980 --> 00:01:44,730 And you know what? 22 00:01:44,730 --> 00:01:48,150 Let's also do a greeting where we say the username here. 23 00:01:48,660 --> 00:01:51,870 So we're going to say, Hey, JJ. 24 00:01:53,570 --> 00:01:54,830 Your password. 25 00:01:56,010 --> 00:01:57,690 Which will be marked in a star. 26 00:01:57,720 --> 00:02:00,510 Is six letters long? 27 00:02:01,570 --> 00:02:08,979 Now, one neat trick here that you haven't learned yet and you might want to use here is this that you 28 00:02:08,979 --> 00:02:10,000 can do with strings? 29 00:02:10,570 --> 00:02:13,690 I can go Star Times. 30 00:02:15,460 --> 00:02:18,430 Make sure that the star is a string. 31 00:02:18,610 --> 00:02:21,070 Multiply it by ten. 32 00:02:21,460 --> 00:02:23,320 And if I print this out. 33 00:02:28,060 --> 00:02:30,480 I get ten stars. 34 00:02:30,490 --> 00:02:36,160 So you may want to use this functionality when we're doing this. 35 00:02:37,210 --> 00:02:38,760 All right, pause the video. 36 00:02:38,770 --> 00:02:39,670 Give it a go. 37 00:02:39,670 --> 00:02:48,280 If you can remember, the goal is to print the username and have the password blocked with how many 38 00:02:48,280 --> 00:02:49,840 characters the password is. 39 00:02:51,490 --> 00:02:52,850 All right, pause the video. 40 00:02:52,870 --> 00:02:55,090 If not, I'm going to get going with the answer. 41 00:02:55,870 --> 00:03:00,850 So the first thing we're going to try and do is I'm going to create two inputs. 42 00:03:01,240 --> 00:03:04,630 So the first one, I'm going to get the username. 43 00:03:05,200 --> 00:03:13,540 I'm going to assign it to the variable username, and it's going to say, What is your username? 44 00:03:14,850 --> 00:03:17,450 Then the second one will be the password. 45 00:03:18,840 --> 00:03:19,850 And the password? 46 00:03:19,860 --> 00:03:20,910 Well, I'll say. 47 00:03:20,940 --> 00:03:23,190 What is your password? 48 00:03:25,320 --> 00:03:30,930 And although this is a simple example, this is something that you will see with other big websites 49 00:03:30,930 --> 00:03:35,070 like Instagram or maybe Netflix when you're logging in. 50 00:03:36,470 --> 00:03:41,360 So now that I've stored this information into a variable, I can use it, right? 51 00:03:41,510 --> 00:03:45,740 I can print and we'll do an F string to make our lives easier. 52 00:03:46,130 --> 00:03:49,280 So I've added the F here, and what we'll do is this. 53 00:03:49,280 --> 00:03:50,120 We'll say. 54 00:03:51,480 --> 00:03:52,450 The username. 55 00:03:53,950 --> 00:03:56,050 Your password. 56 00:03:56,870 --> 00:03:59,840 And we'll add the password here. 57 00:04:01,970 --> 00:04:05,090 Is and then we'll add. 58 00:04:05,950 --> 00:04:07,930 Another variable here. 59 00:04:09,240 --> 00:04:12,090 Which is the password length. 60 00:04:12,600 --> 00:04:14,880 So how are we going to calculate that? 61 00:04:15,540 --> 00:04:17,029 Well, let's try something here. 62 00:04:17,040 --> 00:04:20,579 Let's see if I can use the length function. 63 00:04:20,579 --> 00:04:23,340 And in here do password. 64 00:04:24,310 --> 00:04:25,450 Let's see what happens here. 65 00:04:27,740 --> 00:04:29,030 What is my username? 66 00:04:29,210 --> 00:04:30,770 Let's go with Andre. 67 00:04:32,270 --> 00:04:33,590 What is my password? 68 00:04:33,620 --> 00:04:36,530 Let's just type in secret here. 69 00:04:37,800 --> 00:04:39,870 And I get Andre your password. 70 00:04:40,590 --> 00:04:43,080 Well, I can't speak English properly. 71 00:04:43,110 --> 00:04:46,360 My password secret is six. 72 00:04:46,380 --> 00:04:47,310 Well, six one. 73 00:04:47,760 --> 00:04:51,150 Let's write six letters long. 74 00:04:52,900 --> 00:04:53,530 Awesome. 75 00:04:53,620 --> 00:05:03,670 So this is working because with an F string I can create or add a python expression in here using the 76 00:05:03,670 --> 00:05:05,320 length password. 77 00:05:05,680 --> 00:05:07,260 But there's an issue here, right? 78 00:05:07,270 --> 00:05:09,190 We don't want to actually print out secret. 79 00:05:09,190 --> 00:05:11,320 We want to print it out in the star form. 80 00:05:11,830 --> 00:05:15,990 And this is a good discussion topic on readability of your code. 81 00:05:16,000 --> 00:05:21,580 Now this is a simple example, but we can make this code a little bit cleaner. 82 00:05:21,970 --> 00:05:27,910 For example, we can break things down so that we'll have password. 83 00:05:29,500 --> 00:05:30,100 Length. 84 00:05:31,270 --> 00:05:32,590 Will be length. 85 00:05:33,660 --> 00:05:34,470 Password. 86 00:05:34,590 --> 00:05:36,150 So we're calculating the length. 87 00:05:36,150 --> 00:05:42,030 So this is going to store six or whatever the input of our password is, and it's nice and descriptive. 88 00:05:42,030 --> 00:05:44,160 It's easy for other developers to understand. 89 00:05:44,430 --> 00:05:45,930 And then in here. 90 00:05:46,610 --> 00:05:57,920 I can also have hidden password, and this hidden password will be the password length. 91 00:05:57,920 --> 00:06:00,920 And we're going to use that star. 92 00:06:02,040 --> 00:06:05,340 String and multiply it by the password length. 93 00:06:05,520 --> 00:06:07,530 Let's make this a little bit bigger. 94 00:06:09,200 --> 00:06:12,800 So that now our code can be understood. 95 00:06:12,830 --> 00:06:15,130 Well, in an easier fashion. 96 00:06:15,140 --> 00:06:16,890 So we have the password length. 97 00:06:16,910 --> 00:06:21,380 So we're going to say username your password password. 98 00:06:21,860 --> 00:06:24,230 But we want to make sure that it's the hidden password. 99 00:06:24,230 --> 00:06:25,880 So we'll copy this over here. 100 00:06:27,710 --> 00:06:34,670 So username your password we're going to print out hidden password is and then we're going to copy password 101 00:06:34,670 --> 00:06:35,150 length. 102 00:06:35,950 --> 00:06:39,190 Now I argue that this reads better. 103 00:06:40,010 --> 00:06:43,980 Because each line is doing something simple. 104 00:06:44,000 --> 00:06:46,820 And then finally, we're printing the output. 105 00:06:47,450 --> 00:06:53,960 And although this is a small, simple example, this idea of readability and making and writing code 106 00:06:53,960 --> 00:06:57,710 that makes sense is an important concept. 107 00:06:58,130 --> 00:06:59,570 So let's see if this works. 108 00:06:59,600 --> 00:07:04,650 I'm going to click Run my username Andre this time around. 109 00:07:04,670 --> 00:07:07,520 My password is going to be super secret. 110 00:07:09,060 --> 00:07:10,320 And look at that, Andre. 111 00:07:10,350 --> 00:07:11,700 Your password does it. 112 00:07:11,720 --> 00:07:14,400 It is 11 letters long. 113 00:07:15,500 --> 00:07:17,150 Good job getting this far. 114 00:07:17,450 --> 00:07:18,650 Hopefully you got that. 115 00:07:19,170 --> 00:07:20,660 I'll see you in the next video.