1 00:00:12,740 --> 00:00:18,710 Hello to all of my students, and in this lecture, we will see the answers for if practice assignments. 2 00:00:18,920 --> 00:00:25,370 So as soon as you open the project, the initial project just right, click on it, create a new file. 3 00:00:25,550 --> 00:00:27,170 You can call it if statements. 4 00:00:29,260 --> 00:00:34,300 Like if state governments practice as such. 5 00:00:35,080 --> 00:00:37,810 And once you do also leave a comment. 6 00:00:43,140 --> 00:00:52,320 So for the first assignment, right, you were asked to create a dictionary right here, create a dictionary. 7 00:00:55,930 --> 00:01:06,880 Of employee's right of employees and just created employees equals curly brackets, and then we have 8 00:01:06,880 --> 00:01:08,010 first one is Jack. 9 00:01:08,470 --> 00:01:11,880 Jack is available for six working hours after him. 10 00:01:11,920 --> 00:01:12,940 We have Russell. 11 00:01:14,320 --> 00:01:21,430 Russell is a valuable thing, working hours, and last but not least, we have Karen, which is a valuable 12 00:01:21,430 --> 00:01:22,420 for two hours. 13 00:01:22,960 --> 00:01:23,410 All right. 14 00:01:23,410 --> 00:01:36,580 So after we have this created, let's try to print it print of an employee's dictionary like that. 15 00:01:36,880 --> 00:01:37,240 All right. 16 00:01:38,930 --> 00:01:44,170 And right here, we have an extra ASCE like that, right? 17 00:01:45,540 --> 00:01:48,970 And let's just do some casting to string. 18 00:01:48,980 --> 00:01:52,490 Then we have employees enter the shrine to. 19 00:01:52,490 --> 00:01:52,730 Right. 20 00:01:52,730 --> 00:01:53,450 Click and run. 21 00:01:54,080 --> 00:01:54,500 All right. 22 00:01:54,500 --> 00:01:54,900 Great. 23 00:01:55,250 --> 00:01:56,930 So our dictionary is ready. 24 00:01:56,930 --> 00:02:00,650 Our basis for the next assignments is, OK, we printed it. 25 00:02:00,650 --> 00:02:03,090 We have a successful print from here. 26 00:02:03,320 --> 00:02:05,630 Let's go to the second assignment right here. 27 00:02:05,660 --> 00:02:07,760 You were asked to find an employee. 28 00:02:10,390 --> 00:02:21,910 Four, five to eight hours use, if so from here, let's just create an if statement and start going 29 00:02:21,910 --> 00:02:26,180 cell by cell, meaning let's start going employee after employee. 30 00:02:26,590 --> 00:02:30,610 So first one is we need to extract a value from the dictionary. 31 00:02:30,820 --> 00:02:32,190 If you don't quite remember. 32 00:02:32,200 --> 00:02:37,500 If you don't recall, you can just go back to the lecture where we discussed collections and inside 33 00:02:37,510 --> 00:02:37,990 collections. 34 00:02:37,990 --> 00:02:39,370 We have studied dictionaries. 35 00:02:39,370 --> 00:02:41,650 You can see how to extract values from there. 36 00:02:41,890 --> 00:02:48,130 Basically, it's done with with square brackets where you just mentioned, Jack, in our case like that. 37 00:02:48,910 --> 00:02:56,620 And we want to find we want to find employees who can work between five to eight hours. 38 00:02:56,770 --> 00:03:01,350 So we're going to do this by using the bigger equal sign like this. 39 00:03:01,690 --> 00:03:04,630 And right here we can mention either or and. 40 00:03:04,720 --> 00:03:06,130 All right, so which one is correct? 41 00:03:06,310 --> 00:03:13,030 Obviously, it's the end because we want to find a value which is bigger than five and smaller or equal 42 00:03:13,180 --> 00:03:13,660 to eight. 43 00:03:14,590 --> 00:03:21,370 So we'll use the and logical operator and again, mentioned here, Jack. 44 00:03:22,210 --> 00:03:23,200 Yeah, like that. 45 00:03:25,710 --> 00:03:29,860 And with Jack, we're through not not really. 46 00:03:30,780 --> 00:03:37,530 We have here also to make bigger equals to eight like this and now we're done with Jack. 47 00:03:37,740 --> 00:03:40,040 All right, let's see here. 48 00:03:40,110 --> 00:03:40,440 Great. 49 00:03:40,680 --> 00:03:41,990 So we don't have any arrow here. 50 00:03:42,000 --> 00:03:48,030 This just the one I wanted to check if we don't have an arrow, because you see right here, we have 51 00:03:48,030 --> 00:03:50,610 like a small red dot indicates an arrow. 52 00:03:50,850 --> 00:03:57,030 Just wanted to verify that the arrow, as we can see it right here, doesn't come from the statement. 53 00:03:57,040 --> 00:03:59,910 So just out of the base here and I see the error is gone. 54 00:03:59,940 --> 00:04:01,680 So this statement is correct. 55 00:04:02,130 --> 00:04:08,010 So, again, we have extracted employee Jack, uh, its value, which is six. 56 00:04:08,370 --> 00:04:11,650 And we asked whether six is bigger than five. 57 00:04:11,850 --> 00:04:12,990 This statement is true. 58 00:04:13,140 --> 00:04:19,140 And also and we want that the value would be smaller than eight. 59 00:04:19,440 --> 00:04:19,770 All right. 60 00:04:19,780 --> 00:04:21,660 So we have both values true here. 61 00:04:21,660 --> 00:04:21,920 Right. 62 00:04:23,460 --> 00:04:24,770 And all right. 63 00:04:24,780 --> 00:04:26,430 So just just let me check. 64 00:04:26,430 --> 00:04:28,380 Just print Zachs, for example. 65 00:04:28,560 --> 00:04:29,610 Just verified. 66 00:04:29,610 --> 00:04:29,790 Right. 67 00:04:29,790 --> 00:04:30,480 Click on one. 68 00:04:30,870 --> 00:04:31,410 Great. 69 00:04:31,410 --> 00:04:33,510 So SSX is printed out. 70 00:04:33,780 --> 00:04:34,230 Great. 71 00:04:34,240 --> 00:04:41,850 So we made this condition successful because actually Jack is the one that fits this because Russell 72 00:04:41,850 --> 00:04:43,830 isn't fitting this in count as well. 73 00:04:44,280 --> 00:04:50,400 But we were asked in the Simon to check every cell so we can just handle with Jack and that's it to 74 00:04:50,400 --> 00:04:51,270 complete the assignment. 75 00:04:51,570 --> 00:04:56,910 We also have to use our IF and again, that's use here, Russell. 76 00:04:59,740 --> 00:05:05,560 And also the same thing, bigger equals to five and the employee. 77 00:05:07,070 --> 00:05:07,760 Russell. 78 00:05:10,730 --> 00:05:12,270 Bigger equals the eight. 79 00:05:13,550 --> 00:05:19,520 And right here, just print, Russell is the man. 80 00:05:21,260 --> 00:05:22,590 For this job. 81 00:05:24,350 --> 00:05:33,110 All right, so after this one, let's create additional alif for, uh, by the way, we forgot. 82 00:05:33,140 --> 00:05:33,830 No, it's OK. 83 00:05:34,190 --> 00:05:39,860 Let's forget a mention here, Karen, and also like this. 84 00:05:40,490 --> 00:05:46,400 And then we're going to do bigger equals the five and employees again, Karen. 85 00:05:48,350 --> 00:05:51,410 Smaller equals to eight. 86 00:05:54,940 --> 00:05:57,910 Take Garen for this shift. 87 00:05:59,230 --> 00:06:08,200 All right, and last but not least, we have the house here, which is the default exit point, right? 88 00:06:09,190 --> 00:06:09,550 All right. 89 00:06:09,550 --> 00:06:15,760 So we are done with this and we have a small error here. 90 00:06:15,760 --> 00:06:19,240 We have a red red color under the here. 91 00:06:19,420 --> 00:06:26,860 And that's because we didn't write anything under the first if they Jack for this one. 92 00:06:27,520 --> 00:06:28,000 All right. 93 00:06:28,450 --> 00:06:29,500 Let's try to run it. 94 00:06:29,500 --> 00:06:31,120 See that we don't have any errors. 95 00:06:31,270 --> 00:06:31,500 Right. 96 00:06:31,540 --> 00:06:32,150 Click and run. 97 00:06:33,070 --> 00:06:33,520 All right. 98 00:06:33,520 --> 00:06:39,220 So thank Jack for this one, because once we go over all the employees, we can see that the value of 99 00:06:39,220 --> 00:06:46,750 Jack is actually bigger than five and smaller or smaller than eight or equals to eight because we're 100 00:06:46,750 --> 00:06:51,670 looking for someone to work five to eight hours and he fits it. 101 00:06:52,090 --> 00:06:53,110 He's value six. 102 00:06:53,290 --> 00:06:59,310 And all the other ones are failing to agree to stand for these requirements. 103 00:06:59,350 --> 00:06:59,630 Right. 104 00:06:59,920 --> 00:07:02,250 So they are failing to stand these requirements. 105 00:07:02,260 --> 00:07:04,750 That's why Jack is selected for this shift. 106 00:07:05,440 --> 00:07:07,360 So we're done for assignment number two. 107 00:07:07,390 --> 00:07:09,490 Let's go straight to assignment number three. 108 00:07:11,110 --> 00:07:18,490 And here we need to find someone to work the weekend, a valuable. 109 00:07:20,620 --> 00:07:27,620 For two or four hours, so this is very crucial because here we have two or four hours. 110 00:07:28,150 --> 00:07:34,480 So again, let's see and extract the values if employee Jack. 111 00:07:37,200 --> 00:07:42,690 And double equals sign, right, because we want exact values of one, two or four. 112 00:07:43,080 --> 00:07:51,660 And also here we want to use the logical operator or because the manager asks for not two to four hours, 113 00:07:52,170 --> 00:07:58,020 it's not like it's not like this two to four hours, meaning we can use three hours. 114 00:07:58,020 --> 00:08:02,100 Also know the manager asks for two or four hours. 115 00:08:02,130 --> 00:08:04,710 This is why we use the logical operator or here. 116 00:08:04,740 --> 00:08:05,040 All right. 117 00:08:05,430 --> 00:08:08,880 And again, employee Jack. 118 00:08:11,320 --> 00:08:19,480 And bring something, Jack is selected for the weekend shift. 119 00:08:20,280 --> 00:08:24,160 We have small red arrow here because I didn't put this sign right. 120 00:08:24,730 --> 00:08:27,100 And then we have if. 121 00:08:29,520 --> 00:08:32,390 And we use the same thing for Russell as well. 122 00:08:35,820 --> 00:08:36,850 Equals, equals. 123 00:08:36,870 --> 00:08:39,730 By the way, here, for God to put equals equals four. 124 00:08:40,350 --> 00:08:40,650 Yeah. 125 00:08:40,650 --> 00:08:42,270 Like this now it's correct. 126 00:08:43,980 --> 00:08:48,780 Rasoul equals to our employee Russell. 127 00:08:52,080 --> 00:08:53,860 Equals equals four as well. 128 00:08:54,180 --> 00:08:58,650 And here printing Russell fits. 129 00:09:00,360 --> 00:09:09,810 For weekend shift and last, we have Karen here and we'll extract her name, her value. 130 00:09:11,610 --> 00:09:19,560 Like this or equal equals equals do or employee Karen. 131 00:09:21,490 --> 00:09:23,040 Equals equals four. 132 00:09:23,830 --> 00:09:32,820 So we're done with Pathé off of the assignment, third assignment, we've we have completed the sub 133 00:09:32,920 --> 00:09:33,690 assignment eight. 134 00:09:33,940 --> 00:09:36,610 So this one, we're done with it right here. 135 00:09:37,590 --> 00:09:41,650 We can also add just to complete completed totally. 136 00:09:41,650 --> 00:09:46,150 Carrer will go work the weekend. 137 00:09:46,600 --> 00:09:46,980 Right. 138 00:09:47,260 --> 00:09:53,470 And at the end, as always, we use an else, which is the default exit point. 139 00:09:54,970 --> 00:09:55,300 Yeah. 140 00:09:56,250 --> 00:09:56,790 Brent. 141 00:09:58,060 --> 00:09:58,600 The. 142 00:09:59,740 --> 00:10:00,400 Alice. 143 00:10:03,060 --> 00:10:05,340 Default exit point. 144 00:10:07,050 --> 00:10:16,740 All right, and now we have some assignment B where the manager asked to see what the exact time that 145 00:10:16,740 --> 00:10:18,050 Karen can work the weekend. 146 00:10:18,210 --> 00:10:25,290 So we have to do some digging inside Karen's if statements, if statement, and we're going to use a 147 00:10:25,290 --> 00:10:26,700 nested if for that one. 148 00:10:26,970 --> 00:10:31,910 So, first of all, we're going to erase this code because we don't want to print anything. 149 00:10:32,250 --> 00:10:34,110 And you know what? 150 00:10:34,110 --> 00:10:37,740 Maybe you can do something like I upgraded that we haven't yet. 151 00:10:38,040 --> 00:10:40,010 We can use we can run several lines here. 152 00:10:40,020 --> 00:10:44,160 So let's bring first of all, let's bring Karen will work will go work that weekend. 153 00:10:44,160 --> 00:10:48,000 And also under this print, we could mention if. 154 00:10:50,480 --> 00:10:51,230 Employee. 155 00:10:53,760 --> 00:10:54,330 Karen. 156 00:10:56,480 --> 00:11:03,990 Equals equals to then Brent no, sorry, then we don't want to do anything. 157 00:11:04,010 --> 00:11:05,470 This was the requirement, right? 158 00:11:05,630 --> 00:11:09,280 So if the nestande if it's true, we don't want to do anything. 159 00:11:09,290 --> 00:11:11,330 And that's why I'm going to insert a pass here. 160 00:11:11,540 --> 00:11:13,760 This was the whole point of the assignments. 161 00:11:13,880 --> 00:11:20,690 And also if Ayliffe employee employees, Karen. 162 00:11:22,550 --> 00:11:22,860 Yep. 163 00:11:25,860 --> 00:11:27,250 Equals equals four. 164 00:11:27,270 --> 00:11:33,540 And also, we don't want to do anything right here, we just want to add a default exit point for that 165 00:11:33,540 --> 00:11:35,160 nested if like this. 166 00:11:35,310 --> 00:11:38,670 So right here, we're going to just add a nested. 167 00:11:40,320 --> 00:11:40,920 Alice. 168 00:11:41,960 --> 00:11:49,640 Brent, and the whole point of assignment three B is just to see that you don't have any arrows, all 169 00:11:49,670 --> 00:11:52,160 right, because if you miss this house, for example. 170 00:11:54,420 --> 00:12:01,350 You know, going to have any error, but I want you to do the whole point here was to use all the parts 171 00:12:01,590 --> 00:12:08,370 that you need to use inside the if, use the F, use the alif, use the nested if you use the default 172 00:12:09,030 --> 00:12:13,500 nested else and also use the parent else right here. 173 00:12:13,500 --> 00:12:15,130 So we have all values right here. 174 00:12:15,180 --> 00:12:15,690 Right here. 175 00:12:16,000 --> 00:12:17,670 Let's try to print it right. 176 00:12:17,670 --> 00:12:18,720 Click and run. 177 00:12:19,650 --> 00:12:19,980 All right. 178 00:12:19,990 --> 00:12:26,820 So first of all, as we already seen before, for the first assignment, Jack took the shift and for 179 00:12:26,820 --> 00:12:31,910 the assignment number three and we have Karen will go work that weekend. 180 00:12:32,100 --> 00:12:34,220 So this code works right here. 181 00:12:34,230 --> 00:12:35,760 We already see that it works. 182 00:12:36,090 --> 00:12:36,400 All right. 183 00:12:36,510 --> 00:12:41,760 This ayliffe was executed before because Karen works for two hours. 184 00:12:41,760 --> 00:12:43,810 We can see it here and the dictionary right here. 185 00:12:44,070 --> 00:12:48,120 So now Karen was selected for the weekend shift because of this one. 186 00:12:48,360 --> 00:12:55,260 And it's enough for only one requirement to be fulfilled because we have our logical operator over here. 187 00:12:55,440 --> 00:12:57,800 So it's enough that this will be false. 188 00:12:57,810 --> 00:12:58,530 We don't care. 189 00:12:58,680 --> 00:12:59,850 But this one is true. 190 00:13:00,000 --> 00:13:01,860 And also all of these are false. 191 00:13:02,070 --> 00:13:07,860 So she was selected to be the one to work the weekend this this code ran. 192 00:13:08,070 --> 00:13:12,240 And also we go inside the nested if right here. 193 00:13:12,540 --> 00:13:13,050 All right. 194 00:13:13,290 --> 00:13:17,490 And we don't want to print anything inside the working hours. 195 00:13:17,610 --> 00:13:17,930 All right. 196 00:13:17,940 --> 00:13:22,940 The boss wanted to know what is the exact time she can work in Karen. 197 00:13:22,950 --> 00:13:24,270 Karen can work two hours. 198 00:13:24,540 --> 00:13:31,400 So also the nested if this code was executed, just to check that the flow of code goes over here, 199 00:13:31,680 --> 00:13:37,230 just want to do the the following thing, just print X, X, X and then run. 200 00:13:38,610 --> 00:13:47,160 And as you can see, this code is executed while the other ELIF is not executed. 201 00:13:47,580 --> 00:13:53,250 You can see if I put it here, the card will not go there and this would not be executed. 202 00:13:53,280 --> 00:13:57,740 You can see the X now is not printed because it work. 203 00:13:57,750 --> 00:13:58,790 It goes through here. 204 00:13:59,220 --> 00:13:59,700 All right. 205 00:13:59,970 --> 00:14:05,310 So and this assignment, the code flow goes from here is false. 206 00:14:05,850 --> 00:14:06,860 This one is false. 207 00:14:07,710 --> 00:14:09,150 This one is true right here. 208 00:14:09,150 --> 00:14:09,690 This is true. 209 00:14:09,690 --> 00:14:10,710 So it goes inside. 210 00:14:10,710 --> 00:14:11,820 It goes through here. 211 00:14:12,750 --> 00:14:15,990 And then we handle the nested if which is all of this part. 212 00:14:16,000 --> 00:14:20,620 So we go from here from top and then it goes straight to the pass right here. 213 00:14:21,030 --> 00:14:21,440 All right. 214 00:14:21,600 --> 00:14:24,240 This thing is not executed at all. 215 00:14:26,220 --> 00:14:27,660 That's that's about it. 216 00:14:27,940 --> 00:14:28,310 All right. 217 00:14:29,520 --> 00:14:36,480 So I think that we have covered all the parts of if statements, all the information that we have learned 218 00:14:36,480 --> 00:14:39,570 in the theory lectures we have covered in these assignments. 219 00:14:39,780 --> 00:14:47,130 I really hope that if you have some trouble, this lecture helped you to see some things more clearly, 220 00:14:47,280 --> 00:14:54,120 because I think here all the small features that f f statements has and how to use nested if inside 221 00:14:54,120 --> 00:14:56,640 the code using a dictionary. 222 00:14:56,640 --> 00:15:03,660 Also, I think this makes you dominators in the if statements part. 223 00:15:03,850 --> 00:15:09,870 And right now we're going to go straight ahead to the next lecture where we start talking about loops. 224 00:15:10,020 --> 00:15:19,620 And also in the loops, we're going to discuss how to use a loop using dictionaries and using and how 225 00:15:19,620 --> 00:15:20,670 to use collections. 226 00:15:20,670 --> 00:15:27,780 In general, we're going to apply collections along with for for loops. 227 00:15:28,140 --> 00:15:29,700 And that's about it. 228 00:15:29,730 --> 00:15:30,060 All right. 229 00:15:30,060 --> 00:15:32,130 Thank you, guys, and see you in the next lecture.