Welcome back.
Let's try and do an exercise to tie everything that we've learned up until now.
Together, we're going to create a password checker.
Now, what we want to do is to create some sort of an input that we're going to ask.
So we're going to use the input function, and here we're going to ask for a username.
Then we're going to ask for another input.
It's going to be the password.
And then at the end with the input we want to print.
Something.
The lines of password.
And then we'll have maybe the actual password in here.
And it will say, is another variable here long.
So what we want to do is the password and then maybe the password.
Length.
So that let's say we printed our username JJ and then we give it a password of secret.
Well, we should print the password.
Secret is one, two, three, four, five, six letters long.
Now, obviously, we don't want to show or display the password, maybe for security reasons.
So we want to convert this secret to one, two, three, four, five, six, two stars.
So your task is to convert these two inputs.
And you know what?
Let's also do a greeting where we say the username here.
So we're going to say, Hey, JJ.
Your password.
Which will be marked in a star.
Is six letters long?
Now, one neat trick here that you haven't learned yet and you might want to use here is this that you
can do with strings?
I can go Star Times.
Make sure that the star is a string.
Multiply it by ten.
And if I print this out.
I get ten stars.
So you may want to use this functionality when we're doing this.
All right, pause the video.
Give it a go.
If you can remember, the goal is to print the username and have the password blocked with how many
characters the password is.
All right, pause the video.
If not, I'm going to get going with the answer.
So the first thing we're going to try and do is I'm going to create two inputs.
So the first one, I'm going to get the username.
I'm going to assign it to the variable username, and it's going to say, What is your username?
Then the second one will be the password.
And the password?
Well, I'll say.
What is your password?
And although this is a simple example, this is something that you will see with other big websites
like Instagram or maybe Netflix when you're logging in.
So now that I've stored this information into a variable, I can use it, right?
I can print and we'll do an F string to make our lives easier.
So I've added the F here, and what we'll do is this.
We'll say.
The username.
Your password.
And we'll add the password here.
Is and then we'll add.
Another variable here.
Which is the password length.
So how are we going to calculate that?
Well, let's try something here.
Let's see if I can use the length function.
And in here do password.
Let's see what happens here.
What is my username?
Let's go with Andre.
What is my password?
Let's just type in secret here.
And I get Andre your password.
Well, I can't speak English properly.
My password secret is six.
Well, six one.
Let's write six letters long.
Awesome.
So this is working because with an F string I can create or add a python expression in here using the
length password.
But there's an issue here, right?
We don't want to actually print out secret.
We want to print it out in the star form.
And this is a good discussion topic on readability of your code.
Now this is a simple example, but we can make this code a little bit cleaner.
For example, we can break things down so that we'll have password.
Length.
Will be length.
Password.
So we're calculating the length.
So this is going to store six or whatever the input of our password is, and it's nice and descriptive.
It's easy for other developers to understand.
And then in here.
I can also have hidden password, and this hidden password will be the password length.
And we're going to use that star.
String and multiply it by the password length.
Let's make this a little bit bigger.
So that now our code can be understood.
Well, in an easier fashion.
So we have the password length.
So we're going to say username your password password.
But we want to make sure that it's the hidden password.
So we'll copy this over here.
So username your password we're going to print out hidden password is and then we're going to copy password
length.
Now I argue that this reads better.
Because each line is doing something simple.
And then finally, we're printing the output.
And although this is a small, simple example, this idea of readability and making and writing code
that makes sense is an important concept.
So let's see if this works.
I'm going to click Run my username Andre this time around.
My password is going to be super secret.
And look at that, Andre.
Your password does it.
It is 11 letters long.
Good job getting this far.
Hopefully you got that.
I'll see you in the next video.