1 00:00:00,390 --> 00:00:01,560 -: Welcome back. 2 00:00:01,560 --> 00:00:04,440 Let's try and do an exercise to tie everything 3 00:00:04,440 --> 00:00:07,140 that we've learned up until now together. 4 00:00:07,140 --> 00:00:10,050 We're gonna create a password checker. 5 00:00:10,050 --> 00:00:14,130 Now what we wanna do is to create some sort 6 00:00:14,130 --> 00:00:15,930 of an input that we're gonna ask. 7 00:00:15,930 --> 00:00:18,466 So we're gonna use the input function 8 00:00:18,466 --> 00:00:23,160 and here we're going to ask for a username. 9 00:00:23,160 --> 00:00:25,950 Then we're going to ask for another input. 10 00:00:25,950 --> 00:00:28,863 It's going to be the password. 11 00:00:30,450 --> 00:00:34,440 And then at the end with the input 12 00:00:34,440 --> 00:00:35,770 we wanna print 13 00:00:36,930 --> 00:00:41,310 something, the lines of password 14 00:00:41,310 --> 00:00:46,170 and then we'll have maybe the actual password in here. 15 00:00:46,170 --> 00:00:51,170 And it will say, is another variable here long. 16 00:00:51,540 --> 00:00:55,500 So what we wanna do is the password 17 00:00:55,500 --> 00:00:59,013 and then maybe the password length. 18 00:01:00,090 --> 00:01:03,490 So that, let's say we printed our username, Jay Jay 19 00:01:04,349 --> 00:01:08,130 and then we give it a password of secret. 20 00:01:08,130 --> 00:01:12,510 Well, we should print the password. 21 00:01:12,510 --> 00:01:14,855 Secret is 22 00:01:14,855 --> 00:01:18,960 1, 2, 3, 4, 5, 6 23 00:01:18,960 --> 00:01:20,523 letters long. 24 00:01:21,840 --> 00:01:26,840 Now, obviously we don't want to show or display the password 25 00:01:28,620 --> 00:01:30,470 maybe for security reasons. 26 00:01:30,470 --> 00:01:35,470 So we wanna convert this secret to 1, 2, 3, 4, 5, 6 27 00:01:35,550 --> 00:01:36,393 to stars. 28 00:01:37,620 --> 00:01:41,610 So your task is to convert 29 00:01:41,610 --> 00:01:42,933 these two inputs. 30 00:01:44,070 --> 00:01:44,903 And you know what? 31 00:01:44,903 --> 00:01:48,810 Let's also do a greeting where we say the username here. 32 00:01:48,810 --> 00:01:51,843 So we're going to say. Hey, jay jay, 33 00:01:53,640 --> 00:01:54,730 your password 34 00:01:56,100 --> 00:02:00,513 which will be marked in a star, is six letters long. 35 00:02:01,710 --> 00:02:04,860 Now, one neat trick here that you haven't learned yet 36 00:02:04,860 --> 00:02:09,210 and you might want to use here, is this, that you can do 37 00:02:09,210 --> 00:02:10,680 with strings. 38 00:02:10,680 --> 00:02:13,683 I can go star times, 39 00:02:15,540 --> 00:02:18,750 make sure that the star is a string 40 00:02:18,750 --> 00:02:23,493 multiply it by 10, and if I print this out, 41 00:02:28,140 --> 00:02:30,660 I get 10 stars. 42 00:02:30,660 --> 00:02:35,190 So you may want to use this functionality when 43 00:02:35,190 --> 00:02:36,153 we're doing this. 44 00:02:37,260 --> 00:02:40,740 All right, pause the video, give it a go if you can. 45 00:02:40,740 --> 00:02:43,710 Remember, the goal is to print the username 46 00:02:43,710 --> 00:02:48,710 and have the password blocked with how many characters 47 00:02:48,750 --> 00:02:49,803 the password is. 48 00:02:50,947 --> 00:02:52,860 All right, pause the video. 49 00:02:52,860 --> 00:02:55,083 If not, I'm gonna get going with the answer. 50 00:02:55,980 --> 00:02:58,500 So the first thing we're gonna try and do 51 00:02:58,500 --> 00:03:00,660 is I'm going to create two inputs. 52 00:03:00,660 --> 00:03:05,280 So the first one, I'm going to get the username 53 00:03:05,280 --> 00:03:08,130 gonna sign it to the variable username 54 00:03:08,130 --> 00:03:12,254 and it's going to say, what is your 55 00:03:12,254 --> 00:03:13,473 username? 56 00:03:14,940 --> 00:03:19,920 Then the second one will be the password and the password. 57 00:03:19,920 --> 00:03:23,163 Well, I'll say, what is your password? 58 00:03:25,410 --> 00:03:27,150 And although this is a simple example 59 00:03:27,150 --> 00:03:30,960 this is something that you will see with other big websites 60 00:03:30,960 --> 00:03:35,043 like Instagram or maybe Netflix when you're logging in. 61 00:03:36,600 --> 00:03:40,230 So now that I've stored this information into a variable 62 00:03:40,230 --> 00:03:41,610 I can use it, right? 63 00:03:41,610 --> 00:03:42,810 I can print 64 00:03:42,810 --> 00:03:46,230 and we'll do an F string to make our lives easier. 65 00:03:46,230 --> 00:03:47,760 So I've added the F here 66 00:03:47,760 --> 00:03:52,300 and what we'll do is this, we'll say username 67 00:03:54,030 --> 00:03:55,140 your 68 00:03:55,140 --> 00:03:55,973 password 69 00:03:57,000 --> 00:03:59,770 and we'll add the password here 70 00:04:01,920 --> 00:04:03,360 is, 71 00:04:03,360 --> 00:04:04,350 and then we'll 72 00:04:04,350 --> 00:04:07,893 add another variable here, 73 00:04:09,360 --> 00:04:12,360 which is the password length. 74 00:04:12,360 --> 00:04:14,823 Hmm. So how are we going to calculate that? 75 00:04:15,660 --> 00:04:17,130 Well, let's try something here. 76 00:04:17,130 --> 00:04:20,670 Let's see if I can use the length function 77 00:04:20,670 --> 00:04:23,313 and in here, do password. 78 00:04:24,330 --> 00:04:25,730 Let's see what happens here. 79 00:04:27,840 --> 00:04:29,340 What is my username? 80 00:04:29,340 --> 00:04:30,753 Let's go with Andre. 81 00:04:32,400 --> 00:04:33,750 What is my password? 82 00:04:33,750 --> 00:04:36,573 Let's just type in secret here. 83 00:04:37,982 --> 00:04:39,873 And I get Andre, your password. 84 00:04:40,710 --> 00:04:43,260 Well, I can't speak English properly. 85 00:04:43,260 --> 00:04:46,380 My password secret is six. 86 00:04:46,380 --> 00:04:47,760 Well, six what? 87 00:04:47,760 --> 00:04:51,093 Let's write six letters long. 88 00:04:52,920 --> 00:04:57,330 Awesome. So this is working because with an F string 89 00:04:57,330 --> 00:05:02,330 I can create or add a Python expression in here 90 00:05:02,940 --> 00:05:05,850 using the length password. 91 00:05:05,850 --> 00:05:07,290 But there's an issue here, right? 92 00:05:07,290 --> 00:05:09,210 We don't wanna actually print out secret. 93 00:05:09,210 --> 00:05:11,910 We wanna print it out in the star form. 94 00:05:11,910 --> 00:05:15,180 And this is a good discussion topping on readability 95 00:05:15,180 --> 00:05:16,170 of your code. 96 00:05:16,170 --> 00:05:20,550 Now, this is a simple example, but we can make this code 97 00:05:20,550 --> 00:05:22,050 a little bit cleaner. 98 00:05:22,050 --> 00:05:25,230 For example, we can break things down so 99 00:05:25,230 --> 00:05:27,790 that we'll have password 100 00:05:29,490 --> 00:05:30,323 length, 101 00:05:31,290 --> 00:05:32,440 we'll be length 102 00:05:33,660 --> 00:05:36,150 password so we're calculating the length. 103 00:05:36,150 --> 00:05:39,210 So this is going to store six or whatever the input 104 00:05:39,210 --> 00:05:42,000 of our password is, and it's nice and descriptive. 105 00:05:42,000 --> 00:05:44,520 It's easy for other developers to understand. 106 00:05:44,520 --> 00:05:48,185 And then in here, I can also 107 00:05:48,185 --> 00:05:49,680 have 108 00:05:49,680 --> 00:05:52,560 hidden password. 109 00:05:52,560 --> 00:05:56,880 And this hidden password will be the 110 00:05:56,880 --> 00:05:57,990 password length. 111 00:05:57,990 --> 00:06:00,880 And we're going to use that star 112 00:06:02,010 --> 00:06:05,580 string and multiply it by the password length. 113 00:06:05,580 --> 00:06:07,450 Let's make this a little bit bigger 114 00:06:09,330 --> 00:06:13,770 so that now our code can be understood well 115 00:06:13,770 --> 00:06:15,330 in an easier fashion. 116 00:06:15,330 --> 00:06:17,010 So we have the password length 117 00:06:17,010 --> 00:06:22,010 so we're gonna say username, your password, password 118 00:06:22,020 --> 00:06:24,240 but we wanna make sure that it's the hidden password. 119 00:06:24,240 --> 00:06:25,893 So we'll copy this over here. 120 00:06:27,780 --> 00:06:29,430 So username, your password 121 00:06:29,430 --> 00:06:32,040 we're gonna print out hidden password is 122 00:06:32,040 --> 00:06:35,103 and then we're going to copy password length. 123 00:06:36,090 --> 00:06:39,070 Now, I argue that this reads better 124 00:06:40,140 --> 00:06:43,889 because each line is doing something simple. 125 00:06:43,889 --> 00:06:47,118 And then finally, we're printing the output. 126 00:06:47,118 --> 00:06:50,340 And although this is a small, simple example 127 00:06:50,340 --> 00:06:52,920 this idea of readability and making 128 00:06:52,920 --> 00:06:57,920 and writing code that makes sense is an important concept. 129 00:06:58,230 --> 00:06:59,640 So let's see if this works. 130 00:06:59,640 --> 00:07:04,640 I'm going to click run my username, Andre, this time around. 131 00:07:04,770 --> 00:07:07,503 My password's going to be super secret. 132 00:07:09,120 --> 00:07:09,953 And look at that. 133 00:07:09,953 --> 00:07:14,403 Andre, your password, da, da da, is 11 letters long. 134 00:07:15,570 --> 00:07:17,490 Good job getting this far. 135 00:07:17,490 --> 00:07:19,200 Hopefully you got that. 136 00:07:19,200 --> 00:07:20,750 I'll see you in the next video.