1 00:00:11,860 --> 00:00:12,490 Hi there. 2 00:00:13,150 --> 00:00:20,440 All right, so I think it's time to see the resolution for the homework assignments regarding objects. 3 00:00:20,690 --> 00:00:27,670 OK, so once you open your chance, create a new module and then we'll start off with showing on the 4 00:00:27,670 --> 00:00:28,160 answers. 5 00:00:28,180 --> 00:00:34,300 OK, so basically what we need to create here is a class. 6 00:00:34,390 --> 00:00:34,980 All right. 7 00:00:35,260 --> 00:00:37,810 And the name of the class would be car. 8 00:00:39,550 --> 00:00:45,680 And then we have the Init method, which is identified, first of all, with a key word def. 9 00:00:46,210 --> 00:00:53,530 Then you have double on the score in it, double under score, and then the self is either completed 10 00:00:53,530 --> 00:00:54,430 automatically. 11 00:00:54,670 --> 00:01:03,520 And then we're going to receive one argument here, which is car data list as asked in the assignment. 12 00:01:04,420 --> 00:01:09,560 And here we're going to have the self parameter and then we have car data list. 13 00:01:09,630 --> 00:01:15,100 OK, same as we declared it one line above and like that. 14 00:01:15,660 --> 00:01:19,420 OK, so basically what we have here is the Init method. 15 00:01:19,570 --> 00:01:28,180 It receives this list and it's converted here into a property of an object of a future object as we're 16 00:01:28,180 --> 00:01:29,050 going to create now. 17 00:01:29,080 --> 00:01:33,830 OK, now we're going to create the classes methods. 18 00:01:33,880 --> 00:01:38,890 OK, first of all, we have insurance calculation. 19 00:01:40,930 --> 00:01:41,590 All right. 20 00:01:43,060 --> 00:01:45,340 And we're going to leave it empty for a second. 21 00:01:45,340 --> 00:01:52,090 And we have their doors closed method, which would tell us whether the doors are closed or not. 22 00:01:52,400 --> 00:01:55,420 We're going to leave them empty for a few moments. 23 00:01:55,690 --> 00:02:00,280 And then we have also def get car data. 24 00:02:01,530 --> 00:02:02,010 All right. 25 00:02:02,320 --> 00:02:05,170 So these are the classes methods. 26 00:02:05,370 --> 00:02:09,910 OK, and then we were asked to create two lists for first. 27 00:02:09,910 --> 00:02:21,370 One is least offered and we have four, the focus list and then we have year of release, current Price 28 00:02:21,490 --> 00:02:24,550 and Ford Focus, which is the name of the car. 29 00:02:24,800 --> 00:02:27,080 The last one is the status of the doors. 30 00:02:27,760 --> 00:02:35,800 OK, also we're going to create an instance of an object which will belong to the car class. 31 00:02:35,940 --> 00:02:44,620 OK, Ford Focus, for instance, and it's going to belong to the car class. 32 00:02:45,310 --> 00:02:50,750 And here we go into place or basically, in other words, to pass this list inside. 33 00:02:51,550 --> 00:02:57,100 So what we completed this at this point is we created a list here. 34 00:02:57,490 --> 00:03:02,500 We passed the list into the instance, OK, to this instance for focus. 35 00:03:02,950 --> 00:03:09,520 And this list was went up inside into the Init method and up in here and then here. 36 00:03:09,670 --> 00:03:12,690 And then it can be used in each of these methods right here. 37 00:03:12,730 --> 00:03:13,150 All right. 38 00:03:13,360 --> 00:03:19,940 And we can create an additional an additional list for Audi three. 39 00:03:20,800 --> 00:03:23,920 This is an instance of Ford Focus. 40 00:03:24,060 --> 00:03:24,490 Right. 41 00:03:25,240 --> 00:03:32,410 And we can create an additional list off the list of ality. 42 00:03:33,030 --> 00:03:35,500 OK, just make it a capital here. 43 00:03:37,050 --> 00:03:40,350 And we have Audi A3 list. 44 00:03:43,410 --> 00:03:51,870 And in here we have what do we have here, we have 2011, 15 thousand Audi A3 45 00:03:54,960 --> 00:04:01,500 and then we have a false for the Dumbledore's status and the same, we're going to create instant's. 46 00:04:05,980 --> 00:04:13,480 Of Audi A3 and we have Audi A3 instance 47 00:04:15,850 --> 00:04:25,510 and I'm sorry, and then like that, and also it belongs to car and we're going to pass this list inside 48 00:04:26,590 --> 00:04:28,310 this instance right here, OK? 49 00:04:28,540 --> 00:04:36,880 So wherever we're going to initiate this instance, this list would come in use and these methods. 50 00:04:37,280 --> 00:04:41,930 And once we once we take this instance and we take this one into use. 51 00:04:42,190 --> 00:04:46,630 So this list would come into use in this method as well. 52 00:04:46,870 --> 00:04:56,170 OK, so we came up with the framework, you might say, for that class instances and the list, which 53 00:04:56,170 --> 00:04:58,940 is the arguments which are passed into the instance. 54 00:04:58,960 --> 00:05:07,340 OK, and now let's go back to the top right here and start making calculations as we expected. 55 00:05:07,360 --> 00:05:07,800 All right. 56 00:05:08,170 --> 00:05:15,940 So first of all, we have self car data and this is our list, OK, so we can extract values out of 57 00:05:15,940 --> 00:05:16,480 our list. 58 00:05:16,720 --> 00:05:21,560 Once we mention self that car, there is a list, index zero. 59 00:05:21,820 --> 00:05:27,250 So if we are using this instance, OK, so we're going to use two thousand five. 60 00:05:27,490 --> 00:05:32,530 And if we are using this instance, sorry, if we're using this instance. 61 00:05:32,530 --> 00:05:35,140 Yeah, we're going to get 2005. 62 00:05:35,350 --> 00:05:40,300 And we if you are using this instance, we're going to get two thousand twenty eleven. 63 00:05:40,580 --> 00:05:41,020 All right. 64 00:05:41,650 --> 00:05:48,790 So we can basically pull out or extract values out of the past list which were passed into the instance 65 00:05:48,790 --> 00:05:49,440 of an object. 66 00:05:49,550 --> 00:05:49,750 Right. 67 00:05:50,710 --> 00:05:57,790 But the developer that will come after after us and we'll read our code will not specifically understand 68 00:05:57,790 --> 00:05:58,570 what this means. 69 00:05:58,750 --> 00:06:06,070 And he will need to go backwards compatibility and see like what this thing means. 70 00:06:06,370 --> 00:06:11,470 And he will need to go over here and then back here and see what this thing means and this thing means. 71 00:06:11,470 --> 00:06:11,770 All right. 72 00:06:12,580 --> 00:06:15,520 So we want our co-workers life to be easier. 73 00:06:16,330 --> 00:06:18,790 And for that, we can create the following thing. 74 00:06:19,030 --> 00:06:27,580 We can create appropriate variables as such and assign these values that value to the variable. 75 00:06:27,730 --> 00:06:29,750 And that way it's more much more readable. 76 00:06:29,770 --> 00:06:30,180 All right. 77 00:06:30,490 --> 00:06:34,010 So we have car price, which is self car. 78 00:06:34,120 --> 00:06:36,190 They the list index one. 79 00:06:36,370 --> 00:06:40,510 And we also have the model that is self car. 80 00:06:40,540 --> 00:06:45,790 The list to OK, so we have index one, which is car price. 81 00:06:46,180 --> 00:06:47,920 You can see it right here, car price. 82 00:06:48,460 --> 00:06:54,170 And you have the model which is index two and you can see it here and here. 83 00:06:54,190 --> 00:07:00,190 OK, and these two lists, this one and this one passed into the instance. 84 00:07:00,220 --> 00:07:00,540 Right. 85 00:07:01,690 --> 00:07:06,440 So we have these variables for our disposal and now we can start calculating. 86 00:07:06,460 --> 00:07:10,840 OK, so the assignment said that if the year off. 87 00:07:12,560 --> 00:07:27,200 Year of release is small or equals 2020, but from the other hand, it's also OK, it's and year of 88 00:07:27,200 --> 00:07:34,400 release is bigger or equals from 2010, right. 89 00:07:37,190 --> 00:07:39,150 So we have this statement right here. 90 00:07:40,100 --> 00:07:48,320 Basically, what we are saying is if the year is smaller than 2000 is in 20, but I'll have a mistake 91 00:07:48,320 --> 00:07:51,520 here, but bigger than 2010. 92 00:07:51,980 --> 00:07:57,590 And we also need to take into consideration the car price, which will get to it in a second. 93 00:07:58,430 --> 00:08:05,170 But you can see here it continues yellow line below the statement that I mentioned here and say that 94 00:08:05,180 --> 00:08:11,800 if and if we just click it and hover, then you can see that Pichon tries to tell something which is 95 00:08:12,230 --> 00:08:15,410 very smart and tries to teach us stuff all the time. 96 00:08:15,720 --> 00:08:18,530 So you can see simplify chain comparison. 97 00:08:19,100 --> 00:08:24,650 Basically, pie chart tells us that we can simplify the statement and I'm going to use it. 98 00:08:24,650 --> 00:08:30,300 You see here the yellow light just going to click it and then simplify chain comparison. 99 00:08:30,650 --> 00:08:33,200 Then once clicking it, boom. 100 00:08:33,530 --> 00:08:39,440 OK, I can see that the comparison statement is shortened and it's much more simplified. 101 00:08:39,680 --> 00:08:40,230 You can see. 102 00:08:40,250 --> 00:08:44,720 No, and then the comparison and then you can see the value. 103 00:08:44,720 --> 00:08:53,320 And it's basically one long statement, but it's much shorter than what we have with the end operator 104 00:08:53,630 --> 00:08:55,490 and this is much easier to understand. 105 00:08:55,940 --> 00:09:03,620 OK, so looking at the assignment, we need also to take into consideration the car price and basically 106 00:09:03,620 --> 00:09:04,850 we're going to do the same thing. 107 00:09:05,810 --> 00:09:11,140 We're going to compare the car price, which should be bigger or equal to six thousand. 108 00:09:11,450 --> 00:09:16,280 But from the other hand, it should be smaller than seventeen thousand like this. 109 00:09:17,060 --> 00:09:26,270 And then we're going to create a new variable and you can call it calculated insurance. 110 00:09:30,770 --> 00:09:36,650 And we were told that the car price multiplied by five percent. 111 00:09:37,490 --> 00:09:42,700 All right, this would be the calculated insurance, OK? 112 00:09:44,670 --> 00:09:45,990 So this way. 113 00:09:47,790 --> 00:09:48,660 Just a second. 114 00:09:53,380 --> 00:10:01,570 Like this, OK, so if the rear of the car is between 2000 and 2020 and the car price is to be between 115 00:10:01,570 --> 00:10:09,620 six and seven, 17 K, so the insurance price should be five percent out of the car's price like this. 116 00:10:09,910 --> 00:10:15,160 So this is the insurance price and all other options else. 117 00:10:17,800 --> 00:10:26,560 The calculated insurance would be car price multiplied by zero zero seven, which is seven percent of 118 00:10:26,590 --> 00:10:27,460 the car price. 119 00:10:27,820 --> 00:10:34,300 And what I would like to do now is also to print the insurance calculated. 120 00:10:36,920 --> 00:10:37,790 Insurance. 121 00:10:39,420 --> 00:10:47,940 Is and we're going to use string formatting here, so we're going to use the percentage and then after 122 00:10:47,940 --> 00:10:54,630 closing the quotation mark, we're going to put additional percentage and then the calculated variable 123 00:10:54,840 --> 00:10:57,760 and then it will be put out from here into here. 124 00:10:57,780 --> 00:10:58,200 All right. 125 00:10:58,770 --> 00:11:02,520 So we finished this method, completely done with it. 126 00:11:02,770 --> 00:11:07,050 OK, and now we can go over to the next method. 127 00:11:07,200 --> 00:11:13,020 We can also use, like calculate the insurance price is calculate the insurance price. 128 00:11:14,900 --> 00:11:15,980 For the model. 129 00:11:20,730 --> 00:11:27,360 OK, so I'm just going to mention here the name of the model, and because we're going to have two variables 130 00:11:27,360 --> 00:11:32,440 mentioned here in the print, so we need to have round the brackets here, OK? 131 00:11:32,820 --> 00:11:37,110 So that way we can put divided by a comma self. 132 00:11:38,370 --> 00:11:43,140 We don't need the self because it's a local variable model like this. 133 00:11:44,030 --> 00:11:49,100 So then this variable will be put out here and this variable would go up in here. 134 00:11:49,740 --> 00:11:52,110 So I think we're good with this method. 135 00:11:52,120 --> 00:11:53,300 We are done with it. 136 00:11:53,310 --> 00:11:53,690 All right. 137 00:11:54,090 --> 00:11:58,530 And then we're going to discuss now of doors closed method. 138 00:11:58,650 --> 00:12:00,540 And in here, things are pretty simple. 139 00:12:00,540 --> 00:12:09,990 We have those those status, which is a new variable, and we are going to pull out the last value out 140 00:12:09,990 --> 00:12:10,650 of the list. 141 00:12:10,910 --> 00:12:18,120 OK, so we have this list and this list and these both lists are passed into the unit method. 142 00:12:18,120 --> 00:12:21,090 So we're going to use the list, OK, from here. 143 00:12:21,300 --> 00:12:27,720 And you can see by going backwards up to the list, the original list that you can see, the last variable 144 00:12:27,720 --> 00:12:31,340 in both lists indicates the door status in the cards. 145 00:12:31,620 --> 00:12:36,120 So we can either mention here index zero. 146 00:12:36,120 --> 00:12:37,440 One, two, three. 147 00:12:37,620 --> 00:12:38,060 Right. 148 00:12:39,020 --> 00:12:45,080 You can either put here and the number three, we can either mention minus one, if you recall, it 149 00:12:45,080 --> 00:12:48,920 means that we're going to extract the best value out of the list. 150 00:12:49,400 --> 00:12:51,290 OK, so this is Dorje status. 151 00:12:52,130 --> 00:12:56,390 And then if Dorje status equals equals true. 152 00:12:58,100 --> 00:12:58,490 Yeah. 153 00:12:59,330 --> 00:13:03,590 Then print doors are closed. 154 00:13:03,920 --> 00:13:17,960 OK, and then if you know what, let's start off with alse Dawes status falls and then we can put doors 155 00:13:17,960 --> 00:13:19,210 are open. 156 00:13:19,220 --> 00:13:19,520 Right. 157 00:13:20,870 --> 00:13:22,370 Well partially. 158 00:13:23,780 --> 00:13:26,200 Partially this answer is correct. 159 00:13:27,830 --> 00:13:28,800 Just a moment. 160 00:13:38,990 --> 00:13:39,840 I don't need it. 161 00:13:39,890 --> 00:13:41,140 OK, sorry about that. 162 00:13:41,690 --> 00:13:50,630 So, like, OK, this statement is is actually partially correct, because basically what I did here 163 00:13:50,630 --> 00:13:55,870 is saying that if I had a true OK, if I had a true inside this cell. 164 00:13:56,090 --> 00:14:03,680 So doors are closed and our doors are open, basically it sounds right, but it's not completely right. 165 00:14:03,680 --> 00:14:06,470 OK, because think of the third option. 166 00:14:06,470 --> 00:14:13,160 If here I'm going to put B, C, OK, not boolean variable, true or false, and God is going to put 167 00:14:13,160 --> 00:14:14,230 a wrong value. 168 00:14:14,270 --> 00:14:21,770 ABC and considering this ABC here, once we were going to execute this method. 169 00:14:22,490 --> 00:14:28,670 So we're going to get those are open, but it's not actually open because it's not a true it's not a 170 00:14:28,670 --> 00:14:31,060 false false argument here. 171 00:14:31,700 --> 00:14:33,460 So that will be completely wrong. 172 00:14:34,370 --> 00:14:40,460 So in order to fix this situation of getting false values here and false printouts, we're going to 173 00:14:40,460 --> 00:14:42,080 do small change. 174 00:14:42,080 --> 00:14:42,430 Right. 175 00:14:42,590 --> 00:14:47,210 So are going to do alif door status false. 176 00:14:48,770 --> 00:14:51,810 And then we're going to have those are open, OK? 177 00:14:51,910 --> 00:14:58,130 And then we're going to have alse and we're going to print wrong value incertain. 178 00:14:58,520 --> 00:14:59,010 All right. 179 00:14:59,270 --> 00:15:05,000 So in this case, once we have ABC and gets up in here, so we're going to check whether it's true, 180 00:15:05,540 --> 00:15:12,860 whether it's false and if it's neither of them is going to go up to down to the house and print out 181 00:15:12,860 --> 00:15:14,510 wrong value, insert it. 182 00:15:14,510 --> 00:15:16,760 OK, this is the most correct answer. 183 00:15:17,330 --> 00:15:21,860 And also, if you're going to be asked in interviews, which I'm sure you're going to be asked about, 184 00:15:22,100 --> 00:15:30,560 like to write some kind of, if else statement, make sure that you cover all options and not just most 185 00:15:30,560 --> 00:15:36,470 options, because if you want to be accepted into a certain position, you need to be accurate. 186 00:15:36,600 --> 00:15:37,010 All right. 187 00:15:37,220 --> 00:15:39,260 So this is an accurate answer. 188 00:15:40,610 --> 00:15:47,060 OK, so let's erase it and put through here again, as it was before. 189 00:15:47,900 --> 00:15:50,150 So we already covered this method as well. 190 00:15:50,390 --> 00:16:02,350 And now I'm just going to print out the car model is percentage as it was released and the year. 191 00:16:02,960 --> 00:16:10,940 OK, I'm not sure that I'm correct regarding all the like, commas here and all that, but I guess this 192 00:16:10,940 --> 00:16:18,350 is the the hang of the assignment of the printout just to use variables and use string formatting on 193 00:16:18,350 --> 00:16:19,650 a couple of variables. 194 00:16:19,670 --> 00:16:19,970 All right. 195 00:16:20,390 --> 00:16:25,640 So I'm just don't remember the accurate sentences I asked you to print. 196 00:16:25,830 --> 00:16:29,240 OK, but I guess it's something like that, OK. 197 00:16:29,360 --> 00:16:31,070 And the year percentage. 198 00:16:31,130 --> 00:16:31,590 Yes. 199 00:16:31,640 --> 00:16:32,900 And it costs. 200 00:16:34,530 --> 00:16:37,770 Percentages and then outside of quotation marks percentage. 201 00:16:39,950 --> 00:16:42,470 Brackets, and then we have self. 202 00:16:44,790 --> 00:16:53,760 This time, I'm going to have the lazy answer, just going to use that the sales of the of the list 203 00:16:53,760 --> 00:16:57,920 without setting up appropriate variables, but it's also the same. 204 00:16:57,930 --> 00:17:04,380 Just want you to see several types of approaches for each answer, OK, for each method so you can see 205 00:17:04,410 --> 00:17:06,210 here self khaleda one. 206 00:17:06,540 --> 00:17:10,170 OK, so let's go over what I wrote here. 207 00:17:10,200 --> 00:17:10,620 All right. 208 00:17:10,860 --> 00:17:17,520 So the car model is OK, we have index to 012. 209 00:17:17,520 --> 00:17:20,280 So the car, the car model is for focus. 210 00:17:20,280 --> 00:17:28,650 For example, it was released that the year off in zero was released at the end of 2005 and it costs. 211 00:17:31,240 --> 00:17:32,150 Five thousand. 212 00:17:32,830 --> 00:17:34,690 So I think we're good here as well. 213 00:17:35,650 --> 00:17:40,000 OK, so we have completed all the methods, content. 214 00:17:40,000 --> 00:17:47,230 And now let's let's, uh, let's try to execute the methods, because here the bottom part, which is 215 00:17:47,230 --> 00:17:52,570 outside of the glass we just declared, list an instance of an object. 216 00:17:52,580 --> 00:17:59,920 But we did not mention the execution of these methods using these instances. 217 00:17:59,920 --> 00:18:00,210 Right. 218 00:18:00,430 --> 00:18:01,510 So let's do it right now. 219 00:18:01,570 --> 00:18:11,470 OK, so execute methods for Audi, not out its Ford Focus instance. 220 00:18:11,800 --> 00:18:13,530 So we have Ford Focus, for instance. 221 00:18:13,540 --> 00:18:17,410 That first one is what, insurance calculation? 222 00:18:18,010 --> 00:18:22,620 OK, and then we have Ford Focus instance and we have doors closed. 223 00:18:23,650 --> 00:18:24,070 Yeah. 224 00:18:24,070 --> 00:18:27,850 And the last one is Ford Focus and we have great car data. 225 00:18:28,340 --> 00:18:36,280 OK, then in between before printing printing out Audi outis execution of methods, I'm going to use 226 00:18:36,280 --> 00:18:39,670 the special keyword which is slash. 227 00:18:39,700 --> 00:18:43,900 And so the printouts will be divided so it won't get mixed up. 228 00:18:44,000 --> 00:18:47,290 OK, so in here we're going to execute. 229 00:18:50,920 --> 00:18:57,580 Methods, oops, methods for four for Audi A3. 230 00:18:57,970 --> 00:19:06,220 Right, so just going to copy all of this and just change the name of the instance for Audi three one 231 00:19:07,210 --> 00:19:08,920 to three. 232 00:19:09,190 --> 00:19:10,510 And we are done. 233 00:19:10,830 --> 00:19:15,120 OK, now let's try to run it and pray that everything's going to be fine. 234 00:19:16,150 --> 00:19:16,870 Where is it? 235 00:19:16,870 --> 00:19:18,430 Car practice answers right here. 236 00:19:21,130 --> 00:19:28,930 All right, so there you have it, so calculated, an insurance price for Ford Motor four for the model 237 00:19:28,930 --> 00:19:36,220 for Focus is three hundred fifty doors are closed because they are closed. 238 00:19:36,250 --> 00:19:36,850 It's true. 239 00:19:37,540 --> 00:19:39,150 The car model is for focus. 240 00:19:39,160 --> 00:19:43,120 It was released for Gothia, a D. 241 00:19:44,720 --> 00:19:46,720 Let me just run it again, OK? 242 00:19:46,910 --> 00:19:54,890 It was released at the year 2005, and it cost 5000, which is correct, and calculation for the insurance 243 00:19:54,890 --> 00:19:55,760 for all the eight three. 244 00:19:55,760 --> 00:19:58,670 Seven hundred fifty doors are open. 245 00:19:58,760 --> 00:20:01,240 OK, because the status of the doors is false. 246 00:20:01,250 --> 00:20:02,390 It means they are open. 247 00:20:03,350 --> 00:20:05,180 And the car model is Audi three. 248 00:20:05,400 --> 00:20:08,120 It was released at the year of 2011. 249 00:20:08,120 --> 00:20:10,790 And it cost two thousand. 250 00:20:10,910 --> 00:20:12,570 It costs fifteen thousand. 251 00:20:13,130 --> 00:20:14,420 So there you have it. 252 00:20:14,420 --> 00:20:24,080 You have coverage of creating a class, OK, creating an init method, using methods of a class. 253 00:20:24,230 --> 00:20:24,770 All right. 254 00:20:25,640 --> 00:20:32,150 Farseeing an argument which is a list into the math, into the instance of an object creating an instance 255 00:20:32,150 --> 00:20:34,390 of an object and executing the methods. 256 00:20:34,640 --> 00:20:42,290 So we basically covered all topics related to creation of an object and using all of its features. 257 00:20:42,920 --> 00:20:46,730 And I think it covers this topic pretty much completely. 258 00:20:47,390 --> 00:20:53,250 I will see you in the next videos and we'll discuss further about object oriented programming. 259 00:20:53,510 --> 00:20:54,620 Thank you and bye bye.