1 00:00:00,110 --> 00:00:03,150 Oh yes and welcome back to another class of our quiz. 2 00:00:04,020 --> 00:00:08,700 So until now we so many things and we talked a lot about the loops. 3 00:00:08,700 --> 00:00:17,840 And my goal today is to practice our for loop a bit more since it's not always easy to understand. 4 00:00:17,880 --> 00:00:22,380 I think with a little bit of practice you guys will see that it's not something that is that hard to 5 00:00:22,380 --> 00:00:23,910 understand. 6 00:00:23,910 --> 00:00:24,110 All right. 7 00:00:24,180 --> 00:00:28,530 So what I present against the to do to them is very simple. 8 00:00:28,540 --> 00:00:35,670 What it will create will create let's say for meals for drinks and for desserts and we'll see all the 9 00:00:35,670 --> 00:00:41,330 combinations that can exist of those four meals drinks and desserts. 10 00:00:41,330 --> 00:00:42,530 So we'll create for it. 11 00:00:42,540 --> 00:00:44,670 Well for each. 12 00:00:44,820 --> 00:00:50,510 And we'll will look at all the different combinations that can exist with those. 13 00:00:50,610 --> 00:00:58,560 Well those elements and we'll use the for loop in this case to be able to create this type of small 14 00:00:58,590 --> 00:01:00,000 application. 15 00:01:00,180 --> 00:01:06,210 So let's start with the first thing we want to do is create our list of objects. 16 00:01:06,630 --> 00:01:13,850 So in this case we'll have our first list that will be named meal. 17 00:01:13,920 --> 00:01:19,620 In this case will have pizza and it will have burger 18 00:01:22,920 --> 00:01:27,920 and we'll have spaghetti. 19 00:01:29,410 --> 00:01:32,780 So if you guys want to add other elements you can. 20 00:01:32,890 --> 00:01:34,900 Well let's just create three of them. 21 00:01:35,250 --> 00:01:38,910 So this way you guys will see what it looks all right. 22 00:01:38,910 --> 00:01:41,980 Next thing we want to have drink. 23 00:01:42,230 --> 00:01:44,340 So what exactly will have as drinks. 24 00:01:44,390 --> 00:01:47,040 That second list will be the drinks. 25 00:01:47,400 --> 00:01:53,230 So in this case we'll have water. 26 00:01:53,370 --> 00:02:03,490 We'll have juice and we'll have cola. 27 00:02:03,570 --> 00:02:03,870 Great. 28 00:02:05,430 --> 00:02:08,970 So our last list in this case will be the desserts 29 00:02:11,840 --> 00:02:12,780 this. 30 00:02:12,960 --> 00:02:19,710 In this case the desserts will be let's say cake then ice cream 31 00:02:26,680 --> 00:02:30,600 and finally chips. 32 00:02:30,600 --> 00:02:30,910 All right. 33 00:02:30,910 --> 00:02:37,730 So we have everything that we need to be able to create our smell. 34 00:02:38,410 --> 00:02:43,330 So right now as I said we want to have all the combinations possible so let's say we can have a pizza 35 00:02:43,510 --> 00:02:48,600 drink have water as a drink in a cake but we can have pizza water and drink and ice cream. 36 00:02:48,670 --> 00:02:53,140 And so my goal right now is really having all the possible combinations. 37 00:02:54,190 --> 00:02:58,640 So what exactly we will do I will do something that is called a nested loop. 38 00:02:58,660 --> 00:03:06,600 So this means that you will put a loop inside of a loop and in our case we'll have three levels of loops. 39 00:03:06,610 --> 00:03:10,180 We'll have the meals the drinks and the desserts. 40 00:03:10,300 --> 00:03:11,730 So how exactly this will work. 41 00:03:11,740 --> 00:03:12,370 Very simple. 42 00:03:12,370 --> 00:03:14,330 All right done for. 43 00:03:14,680 --> 00:03:17,550 This will be for our first loop for the meals. 44 00:03:17,560 --> 00:03:23,740 So in this case we have to write down let's say a variable but we'll write down M so our variable will 45 00:03:23,740 --> 00:03:26,820 be m in meals. 46 00:03:26,890 --> 00:03:29,740 So we'll use the first letter of meal just to name the variable 47 00:03:32,770 --> 00:03:37,700 then for this will be our second loop. 48 00:03:37,720 --> 00:03:40,550 In this case the drinks. 49 00:03:40,720 --> 00:03:54,590 So the variable will be D and drink two points for C and this will be our third level of loops. 50 00:03:55,640 --> 00:04:02,390 In this case we'll have the S for desserts in desserts 51 00:04:08,110 --> 00:04:09,280 two points. 52 00:04:09,280 --> 00:04:09,550 All right. 53 00:04:09,850 --> 00:04:12,000 So right now we have our three levels of loop. 54 00:04:12,040 --> 00:04:17,440 We could have started with the desserts then when two drinks went to milk two meals it doesn't really 55 00:04:17,440 --> 00:04:18,170 matter. 56 00:04:18,250 --> 00:04:19,040 The. 57 00:04:19,940 --> 00:04:23,440 In this case the the order doesn't really matter. 58 00:04:23,620 --> 00:04:25,600 But we decided to go in this order. 59 00:04:25,600 --> 00:04:29,290 So we started with meals drinks and desserts. 60 00:04:29,290 --> 00:04:31,150 So it's very simple what's going to happen. 61 00:04:31,150 --> 00:04:33,340 So python will start with beans and water. 62 00:04:33,340 --> 00:04:36,920 So at first we'll have in the water and the pizza water will be tested. 63 00:04:36,930 --> 00:04:43,360 Cake ice cream chips then we'll have pizza and juice and pizza and juice will be taste and taste tested 64 00:04:43,360 --> 00:04:50,260 with cake ice cream and chips and it will go on all right so we have all this right now. 65 00:04:50,290 --> 00:04:51,910 It's time to print our output. 66 00:04:51,910 --> 00:04:53,860 So what exactly want as an output. 67 00:04:53,860 --> 00:04:54,910 So it's very simple. 68 00:04:54,940 --> 00:04:59,510 We'll print what exactly will print. 69 00:04:59,670 --> 00:05:01,800 We'll print a sentence. 70 00:05:01,800 --> 00:05:05,250 So let's say I will have 71 00:05:10,610 --> 00:05:11,180 what exactly. 72 00:05:11,210 --> 00:05:11,750 I will have. 73 00:05:11,990 --> 00:05:17,210 So I will have em which is our variable for a meal as. 74 00:05:17,450 --> 00:05:22,740 So M will be as I said our variable for you as a meal. 75 00:05:23,090 --> 00:05:25,180 So don't forget the M will always change 76 00:05:30,500 --> 00:05:34,140 next. 77 00:05:34,250 --> 00:05:35,210 I also 78 00:05:39,290 --> 00:05:47,380 want in this case will be it will have the D as a drink 79 00:05:50,120 --> 00:05:51,490 as a drink 80 00:05:57,930 --> 00:05:58,320 and 81 00:06:06,590 --> 00:06:08,140 d s as a dessert 82 00:06:12,430 --> 00:06:18,250 as a dessert grape. 83 00:06:18,540 --> 00:06:24,250 So as you can see guys this will be our sentence and this completes our app. 84 00:06:24,280 --> 00:06:31,180 So let's run the app and see all the possible outputs that can happen you can see all the possible outputs 85 00:06:31,270 --> 00:06:34,530 are here so you can have a pizza as a meal. 86 00:06:34,810 --> 00:06:36,830 You also can have water as a drink. 87 00:06:36,850 --> 00:06:41,240 And finally cake as a dessert and as you can see the what. 88 00:06:41,710 --> 00:06:42,970 What happens also. 89 00:06:42,970 --> 00:06:43,810 So it starts with me. 90 00:06:43,870 --> 00:06:51,070 So the first ones will be pizza pizza and with water and the only thing that will change is the dessert. 91 00:06:51,100 --> 00:06:58,060 After that we'll have juice as I explain pizza water then cake ice cream chips then we'll have pizza 92 00:06:58,420 --> 00:07:05,530 juice then cake ice cream chips then there's gonna be pizza cola cake ice cream chips because we start 93 00:07:05,620 --> 00:07:14,260 with the m as with that with me as our first full as you can see guys this is the output and right here 94 00:07:14,530 --> 00:07:20,710 we have all the possible combinations of those three elements and you can write down as many elements 95 00:07:20,770 --> 00:07:22,190 as you guys want. 96 00:07:22,230 --> 00:07:22,900 You can see guys. 97 00:07:22,930 --> 00:07:26,290 This is a way that you can use the for loop. 98 00:07:26,290 --> 00:07:29,170 For example you are looking for a combination of something. 99 00:07:29,200 --> 00:07:35,560 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 100 00:07:35,560 --> 00:07:36,040 class.