Oh yes and welcome back to another class of our quiz.
So until now we so many things and we talked a lot about the loops.
And my goal today is to practice our for loop a bit more since it's not always easy to understand.
I think with a little bit of practice you guys will see that it's not something that is that hard to
understand.
All right.
So what I present against the to do to them is very simple.
What it will create will create let's say for meals for drinks and for desserts and we'll see all the
combinations that can exist of those four meals drinks and desserts.
So we'll create for it.
Well for each.
And we'll will look at all the different combinations that can exist with those.
Well those elements and we'll use the for loop in this case to be able to create this type of small
application.
So let's start with the first thing we want to do is create our list of objects.
So in this case we'll have our first list that will be named meal.
In this case will have pizza and it will have burger
and we'll have spaghetti.
So if you guys want to add other elements you can.
Well let's just create three of them.
So this way you guys will see what it looks all right.
Next thing we want to have drink.
So what exactly will have as drinks.
That second list will be the drinks.
So in this case we'll have water.
We'll have juice and we'll have cola.
Great.
So our last list in this case will be the desserts
this.
In this case the desserts will be let's say cake then ice cream
and finally chips.
All right.
So we have everything that we need to be able to create our smell.
So right now as I said we want to have all the combinations possible so let's say we can have a pizza
drink have water as a drink in a cake but we can have pizza water and drink and ice cream.
And so my goal right now is really having all the possible combinations.
So what exactly we will do I will do something that is called a nested loop.
So this means that you will put a loop inside of a loop and in our case we'll have three levels of loops.
We'll have the meals the drinks and the desserts.
So how exactly this will work.
Very simple.
All right done for.
This will be for our first loop for the meals.
So in this case we have to write down let's say a variable but we'll write down M so our variable will
be m in meals.
So we'll use the first letter of meal just to name the variable
then for this will be our second loop.
In this case the drinks.
So the variable will be D and drink two points for C and this will be our third level of loops.
In this case we'll have the S for desserts in desserts
two points.
All right.
So right now we have our three levels of loop.
We could have started with the desserts then when two drinks went to milk two meals it doesn't really
matter.
The.
In this case the the order doesn't really matter.
But we decided to go in this order.
So we started with meals drinks and desserts.
So it's very simple what's going to happen.
So python will start with beans and water.
So at first we'll have in the water and the pizza water will be tested.
Cake ice cream chips then we'll have pizza and juice and pizza and juice will be taste and taste tested
with cake ice cream and chips and it will go on all right so we have all this right now.
It's time to print our output.
So what exactly want as an output.
So it's very simple.
We'll print what exactly will print.
We'll print a sentence.
So let's say I will have
what exactly.
I will have.
So I will have em which is our variable for a meal as.
So M will be as I said our variable for you as a meal.
So don't forget the M will always change
next.
I also
want in this case will be it will have the D as a drink
as a drink
and
d s as a dessert
as a dessert grape.
So as you can see guys this will be our sentence and this completes our app.
So let's run the app and see all the possible outputs that can happen you can see all the possible outputs
are here so you can have a pizza as a meal.
You also can have water as a drink.
And finally cake as a dessert and as you can see the what.
What happens also.
So it starts with me.
So the first ones will be pizza pizza and with water and the only thing that will change is the dessert.
After that we'll have juice as I explain pizza water then cake ice cream chips then we'll have pizza
juice then cake ice cream chips then there's gonna be pizza cola cake ice cream chips because we start
with the m as with that with me as our first full as you can see guys this is the output and right here
we have all the possible combinations of those three elements and you can write down as many elements
as you guys want.
You can see guys.
This is a way that you can use the for loop.
For example you are looking for a combination of something.
Well this is a way that you guys can find it out so that's it for this class guys and C and our next
class.