1 00:00:00,830 --> 00:00:05,010 OK guys and welcome back to another class of our course about Python. 2 00:00:05,010 --> 00:00:12,120 So we saw anything in the past few classes and today I want to put everything into practice to be able 3 00:00:12,120 --> 00:00:17,770 to well to show you what you guys have learned until now. 4 00:00:17,850 --> 00:00:24,720 So my goal today is really to practice the while loop and also to practice the if statement everything 5 00:00:24,810 --> 00:00:27,210 in one exercise. 6 00:00:27,210 --> 00:00:30,240 So what I think about was let's say passwords. 7 00:00:30,540 --> 00:00:35,790 So for example you are going on Facebook and you start trying you tried password. 8 00:00:35,820 --> 00:00:41,070 So let's say you try one times two times three times four times and other certain moment your account 9 00:00:41,100 --> 00:00:42,480 is blocked. 10 00:00:42,480 --> 00:00:46,900 And if you get the right password well your account will work. 11 00:00:46,900 --> 00:00:50,760 So I decided for this. 12 00:00:50,940 --> 00:00:59,150 Well for this class to create a small app like this would you guys will be able to let's say a practice 13 00:00:59,170 --> 00:01:04,680 in the create a password and we'll also be able to control the number of tries the Mac. 14 00:01:04,680 --> 00:01:07,820 Well the max amount of trace and the what exactly. 15 00:01:07,820 --> 00:01:14,020 All right our user if the account is blocked or the access is granted so let's start. 16 00:01:14,870 --> 00:01:19,830 So very simple for this exercise will need to work to that at times. 17 00:01:19,850 --> 00:01:23,460 So basically we'll need strings and numbers. 18 00:01:24,020 --> 00:01:25,670 We'll need five variables. 19 00:01:25,670 --> 00:01:29,130 So in this case the first variable will be our password. 20 00:01:29,270 --> 00:01:30,920 So we'll write down our password 21 00:01:40,460 --> 00:01:44,850 and our password will be let's say you decide the parts that you want so let's say it's going to be 22 00:01:44,850 --> 00:01:46,910 plus one two three. 23 00:01:47,480 --> 00:01:50,030 Once again the password can be anything you want. 24 00:01:50,420 --> 00:01:53,060 After that the answer that the person will give. 25 00:01:53,060 --> 00:01:55,070 So in this case we'll name this variable. 26 00:01:55,070 --> 00:01:55,850 Your answer 27 00:02:02,480 --> 00:02:04,250 and here you can. 28 00:02:04,250 --> 00:02:05,240 You you write nothing. 29 00:02:05,270 --> 00:02:08,070 So there will be absolutely nothing. 30 00:02:08,080 --> 00:02:10,750 The third variable will be the number of tries. 31 00:02:10,880 --> 00:02:14,690 Because we need we want to have a certain number of tries. 32 00:02:14,690 --> 00:02:19,070 So right now we will be a try number zero because we didn't try. 33 00:02:19,240 --> 00:02:24,570 But after the first try we're gonna be at number one after two tries we'll be at number two after two 34 00:02:24,590 --> 00:02:26,960 three tries will be at number three. 35 00:02:26,990 --> 00:02:34,060 So once again the number of tries will grow as much as we are trying to get the right password. 36 00:02:34,460 --> 00:02:42,820 So you will write down a number of tracks and in this case we start at zero. 37 00:02:42,830 --> 00:02:48,430 If you guys start at 1 and the young max number of tracks will be let's say 10. 38 00:02:48,500 --> 00:02:55,210 In this case your you will have well it's gonna be it's gonna You will have nine tries. 39 00:02:55,250 --> 00:03:00,410 This means you'll have nine trains because it's gonna be nine or ten minus one. 40 00:03:00,410 --> 00:03:00,680 All right. 41 00:03:00,680 --> 00:03:02,990 So a number of tries we are at zero. 42 00:03:03,200 --> 00:03:05,610 So we didn't do no trace at all. 43 00:03:05,630 --> 00:03:07,070 So no max of trace. 44 00:03:07,160 --> 00:03:12,270 This is for example the number Max that you want to have try. 45 00:03:12,270 --> 00:03:14,420 So let's say you want to have Max five tries. 46 00:03:14,450 --> 00:03:15,770 Well it's gonna be here. 47 00:03:16,070 --> 00:03:26,450 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 48 00:03:29,130 --> 00:03:34,140 and finally our last viable will be Max trade. 49 00:03:34,410 --> 00:03:38,440 And in this case it's gonna be a string we'll call it not reached. 50 00:03:39,120 --> 00:03:44,850 So if the max trade is reached this means we'll have a certain output. 51 00:03:44,910 --> 00:03:47,330 And if it's not reached we'll have another output. 52 00:03:47,330 --> 00:03:50,580 So in this case Max Trey will be not reached 53 00:03:53,150 --> 00:03:53,610 Rick 54 00:03:58,090 --> 00:03:58,550 All right. 55 00:03:58,550 --> 00:03:58,890 Great. 56 00:03:59,480 --> 00:04:03,880 So those are our variables so we'll be able to create are up right now. 57 00:04:03,950 --> 00:04:05,550 We have everything that we need. 58 00:04:05,630 --> 00:04:09,880 We have our strings and our numbers so we can start creating our app. 59 00:04:09,890 --> 00:04:15,800 So as I explain what we want to do is we want to give our user direct what our user the opportunity 60 00:04:16,040 --> 00:04:19,590 to trade passwords until he gets there right. 61 00:04:20,120 --> 00:04:26,960 So if our user tries a well trace this password and more than eight times in this case he will simply 62 00:04:27,040 --> 00:04:30,350 it will simply block so the account will be blocked. 63 00:04:30,350 --> 00:04:35,690 So let's write everything down so the first thing we want to do is write down our while loop. 64 00:04:35,990 --> 00:04:37,100 So in this case we'll write down. 65 00:04:38,660 --> 00:04:40,730 And it's gonna be your answer. 66 00:04:40,730 --> 00:04:45,470 So if your answer your answer 67 00:04:50,020 --> 00:04:54,060 is not equal to our password. 68 00:05:00,200 --> 00:05:02,960 We will we run the app again again and again. 69 00:05:02,960 --> 00:05:08,150 So this will be our first condition so as you can see the first condition is your answer is not equal 70 00:05:08,150 --> 00:05:09,160 to our password. 71 00:05:09,170 --> 00:05:16,840 So if this variable is not equal to this variable we will rerun our well our app. 72 00:05:16,970 --> 00:05:25,980 So we will give our our person who is trying the person the opportunity so to try again so this is our 73 00:05:25,980 --> 00:05:31,650 first condition and our second condition is that Max try will not be reached. 74 00:05:31,800 --> 00:05:39,730 So here right now it's not reached but if Max trade is reached well this means that that we have we 75 00:05:39,780 --> 00:05:42,370 can't try anymore. 76 00:05:42,510 --> 00:05:55,500 So in this case Max try is not equal to reached great. 77 00:05:57,300 --> 00:06:01,690 So this is our this is our basic app. 78 00:06:01,770 --> 00:06:03,480 So in this case let me explain once again. 79 00:06:03,480 --> 00:06:04,860 So what does all this mean. 80 00:06:04,860 --> 00:06:14,190 So if your answer is not equal to our password in this case this viable is not equal to this variable 81 00:06:15,090 --> 00:06:17,210 and Max try. 82 00:06:17,480 --> 00:06:20,340 So in this case Max try is not equal to reach. 83 00:06:20,360 --> 00:06:22,520 So right now it's equal to not reached. 84 00:06:22,520 --> 00:06:25,670 We will rerun the app again again and again. 85 00:06:25,700 --> 00:06:29,910 So we'll rerun the code that we'll have right here. 86 00:06:29,910 --> 00:06:30,350 All right. 87 00:06:30,710 --> 00:06:35,510 So what is the first thing that we will need to verify in Oracle. 88 00:06:35,510 --> 00:06:41,750 So in this case we want the number of tries we want the number of tries being less than the number max 89 00:06:41,750 --> 00:06:42,600 of tricks. 90 00:06:42,620 --> 00:06:49,580 So we want this number to always be less than this number because if this number becomes greater than 91 00:06:49,580 --> 00:06:54,050 this number this means that the number of tries have been reached. 92 00:06:54,140 --> 00:06:56,780 So in this case let's say for example we have eight. 93 00:06:56,780 --> 00:06:58,170 What we have eight tries. 94 00:06:58,220 --> 00:07:03,530 So if this number because greater than this number this means we have reached a trace and the app should 95 00:07:03,530 --> 00:07:05,140 stop working. 96 00:07:05,420 --> 00:07:07,700 So the writer will write this down. 97 00:07:07,700 --> 00:07:11,630 So we write down our if statement and we can write down our number 98 00:07:14,990 --> 00:07:15,560 of today's 99 00:07:19,530 --> 00:07:26,750 has to be greater than the number max of trades here. 100 00:07:28,230 --> 00:07:31,020 So we have our if conditions right here So right now. 101 00:07:31,020 --> 00:07:37,050 Well if the statements are so our if statement sets if the number of trades is greater than the number 102 00:07:37,140 --> 00:07:38,420 max of tracks. 103 00:07:38,510 --> 00:07:39,720 So number of trades. 104 00:07:39,780 --> 00:07:40,880 No Max of trades. 105 00:07:40,980 --> 00:07:41,800 If this number. 106 00:07:41,850 --> 00:07:53,610 Well if zero becomes greater than eight what we want to do right here we'll ask our user to enter his 107 00:07:53,610 --> 00:07:53,910 answer. 108 00:07:53,910 --> 00:07:57,390 So right now we'll ask our user to enter his answer. 109 00:07:57,390 --> 00:08:02,910 So in this case our user will enter a certain answer and if his falls well we got to rerun the app 110 00:08:07,850 --> 00:08:08,360 right now. 111 00:08:08,360 --> 00:08:13,770 Your answer will be equal to once again input. 112 00:08:14,030 --> 00:08:16,880 Since we are asking our user to enter a certain answer 113 00:08:19,850 --> 00:08:23,240 what is the password. 114 00:08:23,230 --> 00:08:23,480 Right. 115 00:08:24,960 --> 00:08:28,300 So until now what have we wrote. 116 00:08:28,410 --> 00:08:35,280 So we have our if statement that says the number of trades has to be less than the number max of trades 117 00:08:35,670 --> 00:08:37,020 and this is one trade. 118 00:08:37,320 --> 00:08:38,220 So your answer. 119 00:08:38,250 --> 00:08:46,390 So our user is trained here so our user trade right now this is calculated as one trades. 120 00:08:46,470 --> 00:08:48,190 How can we calculate this as one trade. 121 00:08:48,390 --> 00:08:49,200 Very simple. 122 00:08:49,240 --> 00:08:55,230 Simply write down the number of trade we'll be equal 123 00:08:58,530 --> 00:09:03,080 to number of trade plus one. 124 00:09:03,150 --> 00:09:03,830 So very simple. 125 00:09:04,080 --> 00:09:09,450 Each time that our user tries again and again and again well we simply add one to the number Max of 126 00:09:09,450 --> 00:09:09,780 trades. 127 00:09:10,080 --> 00:09:13,650 So as you can see here we have our a number of trades will group by 1. 128 00:09:13,650 --> 00:09:18,320 So each time that our user is having a well it's it's false. 129 00:09:18,360 --> 00:09:20,250 What's happening here is false. 130 00:09:20,430 --> 00:09:23,300 We'll have he let us have one try one more track. 131 00:09:23,310 --> 00:09:29,130 So in this case let's say for example the answer is not the best one to treat while the number of trades 132 00:09:29,190 --> 00:09:30,150 will grow by 1. 133 00:09:30,300 --> 00:09:34,120 And when it's going to reach 8 well it's over. 134 00:09:34,200 --> 00:09:41,770 So right now this is our if statement if statement so he says this and indicates that this is false. 135 00:09:41,770 --> 00:09:44,840 So in the case that this is not respected. 136 00:09:44,900 --> 00:09:49,760 So in the case that the number of trades becomes greater than the number Max of trades. 137 00:09:50,030 --> 00:09:55,830 What we want to do is return Max trades will be reached. 138 00:09:55,830 --> 00:10:00,840 So in this case next train will be reached 139 00:10:08,290 --> 00:10:08,630 all right. 140 00:10:09,110 --> 00:10:13,500 So let me explain right now we have our if statement in our loop. 141 00:10:13,990 --> 00:10:16,010 So this is our basic quote. 142 00:10:16,060 --> 00:10:21,280 So what it says the number of tribes has to be less than the number mix of tribes. 143 00:10:21,400 --> 00:10:26,690 In this case what is one tribe is one tribe is simply one answer. 144 00:10:26,710 --> 00:10:28,690 So if the answer is false. 145 00:10:28,690 --> 00:10:29,580 Eight times in a row. 146 00:10:29,920 --> 00:10:31,590 What's gonna happen. 147 00:10:31,900 --> 00:10:38,140 Basically this condition will not be met anymore because each time that this we try one input it groups 148 00:10:38,230 --> 00:10:42,760 are called by one because we return this and is going to. 149 00:10:43,030 --> 00:10:47,500 And that because of the while loop what's going to happen we will restart the code again again again 150 00:10:47,590 --> 00:10:51,920 again and again and the number of tribes will become greater and greater and greater. 151 00:10:52,040 --> 00:10:53,530 And census becomes greater. 152 00:10:53,530 --> 00:10:57,670 It's going to become greater than the number mix of tribes and in the case that the number of tribes 153 00:10:57,700 --> 00:11:00,210 becomes greater than the number max of tribes. 154 00:11:00,220 --> 00:11:02,830 We will return Max tries reached. 155 00:11:02,830 --> 00:11:08,840 And if Max trace is equal to reached right now we need to write another line of code to explain what's 156 00:11:08,860 --> 00:11:11,260 going to happen. 157 00:11:11,280 --> 00:11:11,560 All right. 158 00:11:14,290 --> 00:11:22,600 So if in this case Max strait is which is reached max tribe is equal to reached 159 00:11:26,410 --> 00:11:29,610 we want to return a town blocked. 160 00:11:29,800 --> 00:11:33,130 So in this case we'll return a count blocked 161 00:11:38,400 --> 00:11:44,020 and in the other case we'll return access granted because in the first case the account will be blocked. 162 00:11:44,050 --> 00:11:45,550 If this is not respected. 163 00:11:45,550 --> 00:11:51,340 So if the number of tribes becomes greater than the number Max of tribes this means that we will return 164 00:11:51,460 --> 00:11:51,920 this. 165 00:11:51,940 --> 00:11:55,180 And if we and reach this means Max tribe becomes reached. 166 00:11:55,180 --> 00:11:58,700 And if Max tribe becomes reached we'll return account blocked. 167 00:11:59,760 --> 00:12:04,450 And in the other case simply we'll return access granted 168 00:12:09,530 --> 00:12:11,930 so this will be the code for our app. 169 00:12:11,960 --> 00:12:15,610 Let me just run it to make sure that it works perfectly. 170 00:12:15,620 --> 00:12:17,060 So what is the password. 171 00:12:17,060 --> 00:12:19,700 So in this case the password let's say it's gonna be one. 172 00:12:19,790 --> 00:12:20,360 So it doesn't. 173 00:12:20,360 --> 00:12:23,280 What is the password as you can see it that asks again. 174 00:12:23,300 --> 00:12:25,100 Because it doesn't work. 175 00:12:25,100 --> 00:12:30,980 So we can write anything we want just to verify if it's gonna be blocked. 176 00:12:30,980 --> 00:12:33,630 So as you can see it says account blocked at the end. 177 00:12:33,710 --> 00:12:39,050 If instead of eight we give it to trace and we run our app. 178 00:12:39,050 --> 00:12:42,130 What is the password to use for it. 179 00:12:42,160 --> 00:12:44,690 So as you can see account blocked. 180 00:12:44,690 --> 00:12:50,250 So let's write the right password to see what it gives us so we can write down pass. 181 00:12:50,320 --> 00:12:51,530 One two three. 182 00:12:51,770 --> 00:12:53,480 As you can see it says access granted. 183 00:12:54,140 --> 00:12:57,970 So as you can see it's well it's maybe a bit complicated. 184 00:12:57,980 --> 00:12:59,590 Let me try to explain to you guys. 185 00:12:59,600 --> 00:13:01,720 So you'll be able to understand a bit more. 186 00:13:01,970 --> 00:13:04,310 So those are our variables. 187 00:13:04,310 --> 00:13:05,230 So we'll be able to. 188 00:13:05,240 --> 00:13:05,640 All right. 189 00:13:06,080 --> 00:13:07,910 Let's talk about the app in particular. 190 00:13:08,840 --> 00:13:17,120 So we'll start with our while loop so our why loop what it says basically are a while loop says if your 191 00:13:17,120 --> 00:13:17,780 answer. 192 00:13:17,780 --> 00:13:22,160 So in this case this variable is not equal to our password. 193 00:13:22,160 --> 00:13:25,540 And Max trade is equal to reached. 194 00:13:25,550 --> 00:13:34,940 So both of those both of those things are respected until both of those things are not respected. 195 00:13:34,970 --> 00:13:39,170 We will rerun this app again again and again. 196 00:13:39,200 --> 00:13:41,970 So what exactly is inside of the app. 197 00:13:41,990 --> 00:13:42,700 Very simple. 198 00:13:43,670 --> 00:13:50,240 So we have a number of tries has to be less than the number Max of trace and where exactly are about 199 00:13:50,240 --> 00:13:51,230 what tries exactly. 200 00:13:51,230 --> 00:13:52,190 Are we talking here. 201 00:13:52,250 --> 00:13:53,780 We're talking about your answer. 202 00:13:53,780 --> 00:13:59,980 So in this case each trade is counted when one false answer is given. 203 00:13:59,990 --> 00:14:04,850 So if one false answer is given as you can see here the number of tries will grow by 1 and then the 204 00:14:04,850 --> 00:14:07,070 number of trades grows by 1. 205 00:14:07,070 --> 00:14:12,390 This means that the number of tries can become greater than the number max of tries. 206 00:14:12,530 --> 00:14:15,640 And in this case we'll return reached. 207 00:14:15,640 --> 00:14:18,860 And as you can see here we'll have reached. 208 00:14:18,860 --> 00:14:21,810 So as you can see both of those things will be respected. 209 00:14:21,860 --> 00:14:25,800 And in this case what's going to happen will be here in our code. 210 00:14:25,820 --> 00:14:30,830 So we'll have our Max try we'll be equal to reached in this case will return account blocked. 211 00:14:31,070 --> 00:14:35,930 And if it's not reached well in this case will return access granted. 212 00:14:36,050 --> 00:14:38,870 So I hope you guys understand that all this. 213 00:14:38,870 --> 00:14:45,110 I tried to put everything together so we put the while loop and as well as the if statement trying to 214 00:14:45,110 --> 00:14:46,300 work with both of those. 215 00:14:46,310 --> 00:14:48,910 So it's a bit more complicated. 216 00:14:49,100 --> 00:14:53,880 So if you guys don't understand it what I suggest you do is simply to re watch this glass. 217 00:14:53,960 --> 00:15:00,050 But besides that it's really a question of practice to just try to practice those well the while loop 218 00:15:00,170 --> 00:15:04,370 and the if statement and at the end you'll see it's not that hard to use. 219 00:15:04,460 --> 00:15:07,460 So that's it for the sports guys and see in our next glass.