-: Welcome back.
Let's try and do an exercise to tie everything
that we've learned up until now together.
We're gonna create a password checker.
Now what we wanna do is to create some sort
of an input that we're gonna ask.
So we're gonna 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 wanna 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 wanna do is the password
and then maybe the password length.
So that, let's say we printed our username, Jay Jay
and then we give it a password of secret.
Well, we should print the password.
Secret is
1, 2, 3, 4, 5, 6
letters long.
Now, obviously we don't want to show or display the password
maybe for security reasons.
So we wanna convert this secret to 1, 2, 3, 4, 5, 6
to 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, jay jay,
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 10, and if I print this out,
I get 10 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 gonna get going with the answer.
So the first thing we're gonna try and do
is I'm going to create two inputs.
So the first one, I'm going to get the username
gonna sign 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 username
your
password
and we'll add the password here
is,
and then we'll
add another variable here,
which is the password length.
Hmm. 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 what?
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 wanna actually print out secret.
We wanna print it out in the star form.
And this is a good discussion topping 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,
we'll 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 gonna say username, your password, password
but we wanna make sure that it's the hidden password.
So we'll copy this over here.
So username, your password
we're gonna 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's going to be super secret.
And look at that.
Andre, your password, da, da da, is 11 letters long.
Good job getting this far.
Hopefully you got that.
I'll see you in the next video.