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