How's everybody doing, OK?
I think it's time to begin giving you the answers of the homework once you tried to get the answers
about yourselves.
If you get into trouble, I'll just you want to verify your results.
You can use this lecture to do it.
OK, so first of all, create a new file, you can call it while loops practice.
And from here, let's begin.
So, first of all, let's add and comment here.
Let's call it while loops practice.
And as you recall, you have bought a Barbie and PERTZYE.
All right, like this and first thing first, you were asked to create a list in poverty and use it
along the way, the items were five, six, twenty four, thirty to twenty one and seventy.
Right.
And also, we need to put some spaces here.
So Python would not be angry at us.
All right.
Like this.
It's nice and beautiful.
And from here, let us create our first wire loop of a OK.
And right here we want to ages to be tested.
And our stop condition is as long as ages is smaller than 30, we should continue on.
All right.
But in this way, we we don't actually test these cells.
So how can we actually extract the cells out of the out of the list?
All right.
So we need to combine some knowledge out of the lists, lectures that we have seen.
And the only way to extract values out of the list is using an index.
Right.
Like doing something like this.
OK, so this is the way to extract values.
So we need somehow to put out a way to enter some parameter here so we could extract values by index.
And if we put, for example, a simple number here, so always this value would be tested again and
again.
But we need something else.
We need something else that on each cycle, this number here would grow.
OK, and the only way to do it is basically to create an additional variable called counter, it's exactly
the hint that it gives you in the previous video and here to place the counter.
So for starts, this value would be zero.
All right.
And from here, let's Sprint Party, for example, for for beginning part A. to have some indication.
And the age is ages counter, OK, with the simple casting here.
All right.
So anybody could guess what will happen if I leave it like this.
OK, let's run it and see.
All right, so we're running this and you can see something happening here is just keeps running and
running.
It will keep running even after the end will after the world will end.
It will keep running.
Or maybe my computer could explode by the result of this because it's not going to stop for for never.
Right.
The reason is, let me stop it before something happens.
All right.
This is what you see here.
This is the classic occasion of endless loop.
You can see the value of five is printed endlessly, probably printed several thousand times for now.
And what happens here?
Basically, we have a discount or tested and the value inside the edges is always zero.
So this value is extracted for eternity because we didn't manage to grow this number by one on each
cycle.
So stuck on zero here and basically print the same value again and again and again endlessly.
OK, so this is a classic, a classic case of endless loop and you must avoid it because this is fail,
failed programming.
You cannot leave loops like this.
OK, so what you want to do here is to make it like this, OK, you want to grow the counter by one
on each cycle and if we run it now.
Simply, you seeing that it's not endless right now.
All right, so as you can see, the stop the stop conditioning here works and it stops as far as to
this value right here, because this value is above 30.
And this is the reason that these values are not printed, because once the values inside here and sell
the Aegis counter is bigger, is bigger than 30, and once this thing became false.
So the wire stops working.
And also you were asked to print outside of the wire loop and the value.
All right.
Print me part A, the value that caused.
Caused the loop to stop.
OK.
So this one was ages counter, and the reason is this printout is outside, the wire loop is right here.
You can see an invention, right?
We declared the wire loop right here.
And every line, it has indention here.
The spaces is inside the way loop.
But once we remove the indention and we go straight from the star here.
So this line is outside the wire loop and we just want to check what number caused the wire to fail
to go out.
All right.
OK, great, so you can see exactly what value caused it to fail, because the loop went again, again,
again and again up until it got to this number and then it exited the wire loop because this statement
was false because this value of 32 went up in here and 32 is not smaller than 30.
And this is what caused the wall to exit and go straight to the flow of code outside the wire loop,
which is Rikyu.
All right, from here in Barbie, you were asked, first of all, to go an empty line before the outboards,
and the simple reason is just to avoid here makes of outputs, just to have some spaces.
And if you recall from previous lectures, it's done by men like this.
Let's just check it.
And you can see that if I put A, B, C here and I have the empty, empty line here, once we print
it.
Oops, once we print it.
OK, so you see empty, empty line right here.
OK, if I remove it.
You see, it's go straight ahead after this printout right here, we don't have any spaces between these
lines.
OK, so we want a separation here.
All right, so in PABI, you were asked to use the same or the same way, just going to copy it from
here.
No need to print it again.
But this time you were also asked to put in if and stop the loop from inside.
Once the ages lowers, the value inside the cells is bigger than 20.
All right.
So age, if if the value inside the list is bigger than 20, then what we want to do first of all,
we want to print the value.
First of all, Part B, bring the value of, uh, that stopped.
The loop, OK, and it goes like this age is counter.
And how do we stop the way from inside, OK?
You had an underlying under the warden's side, so the way to do it is exactly what we have seen in
the advanced lecture theory is use a break, OK, just to make sure the brake worked also.
You know what?
Let me ask you something.
OK, before taking the break and everything.
Let me ask you something.
Is this is this code correct?
Is this flow from top to bottom here?
Correct.
Something is wrong here.
OK, I will give you a hint.
We declare counter equals zero out here.
Then we go over a few loops here and we go up until this line right here.
Correct.
So once we are finished with this loop, we go straight ahead to this to this place right here.
What do you think the first value of counter is here?
Whether do you think the first value that will appear inside these square brackets here, let's test.
How do we do it?
Let's just print counter.
OK, I'm just going to I'm just one.
I just want to check what value of counter will go here.
So I'm going to print it before it got to the wild.
I have a printout right here just for me.
OK, it's debugging just for me to know what is the value here.
OK, let's run it and see what happens.
As you can see, the value here is three.
OK, so this is wrong coding, this is wrong.
This is false because we want to start the loop fresh from the first cell off the list and we starting
here from here, OK?
Because what we haven't done and we should do is just going to erase it.
We should before starting another while loop.
We should use calendar equals zero to zeros because once it's zero, it start from the cell, from the
index, zero from here.
OK, and if you do not put counter equals zero here, just going to start from the counter where it's
left and we left it at value equals three.
OK, and this is false.
All right.
And also, you can see the PABI here was not printed at all because as it got here to the beginning
of the loop, it already went out of the loop because the first value that was accepted right here is
32.
And obviously this this gold right here didn't run event because it straight ahead went outside of the
loop.
OK, now that we have counter equals zero, let's just put it under Bombi.
All right, so now we can run it.
OK, still, we have some problem, you can see that nothing is printed right here.
Let's see, why do we have this problem?
Oh, all right.
Also, we forgot something very important.
Again, you forgot to do this.
Right.
All right.
We are growing the counter variable by one on each cycle.
And there you go.
All right, so what we actually do here is use the break action key, as we have seen in the advanced
report regarding why loops and what happens here is we stop the loop from inside.
This was our mission, OK?
And once the value was over 20, this was the cause of our why loop to stop running and as we were asked
as well, were needed to print the value that caused this stop.
OK, so the value caused the Y look to run is twenty four.
Twenty four is indeed bigger than twenty.
And this is what made the Y look to stop running.
And as you can see, nothing else here was printed, only the value twenty four which is this printout.
OK.
And right after this print out we had a break here so nothing else.
Rund ran inside this wall.
OK, so the wire loop exited once you got to this break.
Action.
OK, and also the reason here that we have to intention's.
All right.
We have one indention using tab and second indention is because the code that we write up in here is
applied under the if OK.
And this thing, for example, the counter plus equals one.
It has one indention because this one is applied under the while and the if does not have any any action
taken upon it.
OK, this thing runs under the wire, only under the wire.
It's invisible to the IV here because only two indentations is the code that is visible to the IF.
All right, so we have completed the second part, we have stopped the while loop from inside as we
were asked and from here we can go straight ahead to assignment number three.
That's do as well here.
The print slash in just we have some order like order in my eyes, order here.
I mean, inside the output and inside here, we again need to make the counter equal zero at the beginning.
All right.
And the thing is that we were asked to do here is, first of all, to create a wire loop and the wire
loop should be with a stop stop condition of sanity like this.
And the next thing we were asked to do is to add plus to OK, to the sales values.
All right.
So we're going to use ages counter, which is this is the sale value.
And again, we're going to use ages counter and do it lasta.
OK, so we're going to take the cell value add plus to it and all of this is going to go straight ahead
inside this cell.
OK, so this cell will change and it will have incited these values.
OK, so once we have completed this thing, let's print out part B or C cells.
New values value is ages counter.
All right.
And again, what we need to do not forget counter loss equals block plus equals one.
All right, and also we were asked to use an else here and see what happens once all the while loop
exits with a number, we should go to parts, see inside or else.
Because of the number
ages count.
All right, so we have an exit point, meaning once this statement is false, so the while loop will
exit itself and will go straight to the yells, OK.
So in in our assignment a here, once the while loop exits, just goes outside of the wire loop completely
goes outside of the wire.
Like this line is not connected to the wire loop at all in any connection.
But here in assignment number C we have created an else statement and once the wire loop will exit,
it will go straight to the L's condition right here.
Let's see what happens.
All right, we have some kind of air in line here.
All right, so let's try to understand it is good practice can only can get an eighth string at the
end of the string.
OK, we also can see here.
Oh, we missed the guesting, of course.
All right, they should be they should be OK.
All right, so you can see here inside the house, so we have been successful resolving policy as well,
what basically happened here, just enlarge it for a second.
So basically what happened here, we went over each of these cells and we have added plus two to each
of them.
So five plus two is seven and six plus two is eight and so on and so on up until we got to number 70.
And we have here a condition that once this number will be false, OK, once this statement will be
false and in our case, 70 here.
So this statement is false, obviously.
And once we have 70 value right here, it will exceed the wire loop and go straight to the yells.
And you can see the reason of getting into really is this number right here, 70, which caused the
wire to exit.
All right.
I think we're done at this point.
This was a bit challenging assignments, I must admit.
But I think it's good to have some challenges in your life, as always.
And also, I just want to mention and remind you again that the reason that you're doing this course
is not for fun.
The reason that you're doing it is to learn Python to become professionals and to become python ninjas.
Some of you want to become front and develop.
Some of you want to become beckoned or even automation developers.
And you must control and dominate these fields.
And I assure you that this is the the highest level of programming regarding these topics that you should
know tricks that you're seeing here in the assignments and in the theory and in the example part, this
will all will be applied once you will start working as programmers and once you will start developing
your own software.
These tricks and these that knowledge will help you a lot, because now I can assure you that you dominate
also the loop's section regarding Python programming language.
All right.
So once we have completed this part, now it's time to go forward to the next topic.
And I will see you in the next video.
Thank you and bye bye.
Good job.