OK guys and welcome back to another class of our course about Python.
So we saw anything in the past few classes and today I want to put everything into practice to be able
to well to show you what you guys have learned until now.
So my goal today is really to practice the while loop and also to practice the if statement everything
in one exercise.
So what I think about was let's say passwords.
So for example you are going on Facebook and you start trying you tried password.
So let's say you try one times two times three times four times and other certain moment your account
is blocked.
And if you get the right password well your account will work.
So I decided for this.
Well for this class to create a small app like this would you guys will be able to let's say a practice
in the create a password and we'll also be able to control the number of tries the Mac.
Well the max amount of trace and the what exactly.
All right our user if the account is blocked or the access is granted so let's start.
So very simple for this exercise will need to work to that at times.
So basically we'll need strings and numbers.
We'll need five variables.
So in this case the first variable will be our password.
So we'll write down our password
and our password will be let's say you decide the parts that you want so let's say it's going to be
plus one two three.
Once again the password can be anything you want.
After that the answer that the person will give.
So in this case we'll name this variable.
Your answer
and here you can.
You you write nothing.
So there will be absolutely nothing.
The third variable will be the number of tries.
Because we need we want to have a certain number of tries.
So right now we will be a try number zero because we didn't try.
But after the first try we're gonna be at number one after two tries we'll be at number two after two
three tries will be at number three.
So once again the number of tries will grow as much as we are trying to get the right password.
So you will write down a number of tracks and in this case we start at zero.
If you guys start at 1 and the young max number of tracks will be let's say 10.
In this case your you will have well it's gonna be it's gonna You will have nine tries.
This means you'll have nine trains because it's gonna be nine or ten minus one.
All right.
So a number of tries we are at zero.
So we didn't do no trace at all.
So no max of trace.
This is for example the number Max that you want to have try.
So let's say you want to have Max five tries.
Well it's gonna be here.
So in this case we'll write down our number max of trade it we'll be here and here let's set it to eight
and finally our last viable will be Max trade.
And in this case it's gonna be a string we'll call it not reached.
So if the max trade is reached this means we'll have a certain output.
And if it's not reached we'll have another output.
So in this case Max Trey will be not reached
Rick
All right.
Great.
So those are our variables so we'll be able to create are up right now.
We have everything that we need.
We have our strings and our numbers so we can start creating our app.
So as I explain what we want to do is we want to give our user direct what our user the opportunity
to trade passwords until he gets there right.
So if our user tries a well trace this password and more than eight times in this case he will simply
it will simply block so the account will be blocked.
So let's write everything down so the first thing we want to do is write down our while loop.
So in this case we'll write down.
And it's gonna be your answer.
So if your answer your answer
is not equal to our password.
We will we run the app again again and again.
So this will be our first condition so as you can see the first condition is your answer is not equal
to our password.
So if this variable is not equal to this variable we will rerun our well our app.
So we will give our our person who is trying the person the opportunity so to try again so this is our
first condition and our second condition is that Max try will not be reached.
So here right now it's not reached but if Max trade is reached well this means that that we have we
can't try anymore.
So in this case Max try is not equal to reached great.
So this is our this is our basic app.
So in this case let me explain once again.
So what does all this mean.
So if your answer is not equal to our password in this case this viable is not equal to this variable
and Max try.
So in this case Max try is not equal to reach.
So right now it's equal to not reached.
We will rerun the app again again and again.
So we'll rerun the code that we'll have right here.
All right.
So what is the first thing that we will need to verify in Oracle.
So in this case we want the number of tries we want the number of tries being less than the number max
of tricks.
So we want this number to always be less than this number because if this number becomes greater than
this number this means that the number of tries have been reached.
So in this case let's say for example we have eight.
What we have eight tries.
So if this number because greater than this number this means we have reached a trace and the app should
stop working.
So the writer will write this down.
So we write down our if statement and we can write down our number
of today's
has to be greater than the number max of trades here.
So we have our if conditions right here So right now.
Well if the statements are so our if statement sets if the number of trades is greater than the number
max of tracks.
So number of trades.
No Max of trades.
If this number.
Well if zero becomes greater than eight what we want to do right here we'll ask our user to enter his
answer.
So right now we'll ask our user to enter his answer.
So in this case our user will enter a certain answer and if his falls well we got to rerun the app
right now.
Your answer will be equal to once again input.
Since we are asking our user to enter a certain answer
what is the password.
Right.
So until now what have we wrote.
So we have our if statement that says the number of trades has to be less than the number max of trades
and this is one trade.
So your answer.
So our user is trained here so our user trade right now this is calculated as one trades.
How can we calculate this as one trade.
Very simple.
Simply write down the number of trade we'll be equal
to number of trade plus one.
So very simple.
Each time that our user tries again and again and again well we simply add one to the number Max of
trades.
So as you can see here we have our a number of trades will group by 1.
So each time that our user is having a well it's it's false.
What's happening here is false.
We'll have he let us have one try one more track.
So in this case let's say for example the answer is not the best one to treat while the number of trades
will grow by 1.
And when it's going to reach 8 well it's over.
So right now this is our if statement if statement so he says this and indicates that this is false.
So in the case that this is not respected.
So in the case that the number of trades becomes greater than the number Max of trades.
What we want to do is return Max trades will be reached.
So in this case next train will be reached
all right.
So let me explain right now we have our if statement in our loop.
So this is our basic quote.
So what it says the number of tribes has to be less than the number mix of tribes.
In this case what is one tribe is one tribe is simply one answer.
So if the answer is false.
Eight times in a row.
What's gonna happen.
Basically this condition will not be met anymore because each time that this we try one input it groups
are called by one because we return this and is going to.
And that because of the while loop what's going to happen we will restart the code again again again
again and again and the number of tribes will become greater and greater and greater.
And census becomes greater.
It's going to become greater than the number mix of tribes and in the case that the number of tribes
becomes greater than the number max of tribes.
We will return Max tries reached.
And if Max trace is equal to reached right now we need to write another line of code to explain what's
going to happen.
All right.
So if in this case Max strait is which is reached max tribe is equal to reached
we want to return a town blocked.
So in this case we'll return a count blocked
and in the other case we'll return access granted because in the first case the account will be blocked.
If this is not respected.
So if the number of tribes becomes greater than the number Max of tribes this means that we will return
this.
And if we and reach this means Max tribe becomes reached.
And if Max tribe becomes reached we'll return account blocked.
And in the other case simply we'll return access granted
so this will be the code for our app.
Let me just run it to make sure that it works perfectly.
So what is the password.
So in this case the password let's say it's gonna be one.
So it doesn't.
What is the password as you can see it that asks again.
Because it doesn't work.
So we can write anything we want just to verify if it's gonna be blocked.
So as you can see it says account blocked at the end.
If instead of eight we give it to trace and we run our app.
What is the password to use for it.
So as you can see account blocked.
So let's write the right password to see what it gives us so we can write down pass.
One two three.
As you can see it says access granted.
So as you can see it's well it's maybe a bit complicated.
Let me try to explain to you guys.
So you'll be able to understand a bit more.
So those are our variables.
So we'll be able to.
All right.
Let's talk about the app in particular.
So we'll start with our while loop so our why loop what it says basically are a while loop says if your
answer.
So in this case this variable is not equal to our password.
And Max trade is equal to reached.
So both of those both of those things are respected until both of those things are not respected.
We will rerun this app again again and again.
So what exactly is inside of the app.
Very simple.
So we have a number of tries has to be less than the number Max of trace and where exactly are about
what tries exactly.
Are we talking here.
We're talking about your answer.
So in this case each trade is counted when one false answer is given.
So if one false answer is given as you can see here the number of tries will grow by 1 and then the
number of trades grows by 1.
This means that the number of tries can become greater than the number max of tries.
And in this case we'll return reached.
And as you can see here we'll have reached.
So as you can see both of those things will be respected.
And in this case what's going to happen will be here in our code.
So we'll have our Max try we'll be equal to reached in this case will return account blocked.
And if it's not reached well in this case will return access granted.
So I hope you guys understand that all this.
I tried to put everything together so we put the while loop and as well as the if statement trying to
work with both of those.
So it's a bit more complicated.
So if you guys don't understand it what I suggest you do is simply to re watch this glass.
But besides that it's really a question of practice to just try to practice those well the while loop
and the if statement and at the end you'll see it's not that hard to use.
So that's it for the sports guys and see in our next glass.