1 00:00:11,740 --> 00:00:14,950 Hi, everybody, I'm very happy that you're here with me. 2 00:00:15,160 --> 00:00:19,990 We will try to resolve and get the answers of inheritance homework assignment. 3 00:00:20,530 --> 00:00:26,140 I guess it was a bit challenging than previous assignments you can compare it to may be assignments 4 00:00:26,140 --> 00:00:28,240 or variables or collections. 5 00:00:28,330 --> 00:00:35,110 So obviously these assignments now are much harder and much more challenging, but there are surely 6 00:00:35,110 --> 00:00:39,520 doable because we went over all the topics in the previous lectures. 7 00:00:40,000 --> 00:00:43,200 OK, so quick overview of what do we need to do? 8 00:00:43,330 --> 00:00:45,250 We need to create two classes. 9 00:00:45,460 --> 00:00:47,770 One of them is the parent employee. 10 00:00:47,950 --> 00:00:51,280 The other one is the programmer, which is the child. 11 00:00:52,300 --> 00:00:55,810 We need to make inheritance between child and parent. 12 00:00:56,140 --> 00:01:02,890 And we also need to create some calculations, methods and also to bring some values. 13 00:01:03,080 --> 00:01:09,250 So once you open by charm, create a new file of OAP inheritance practice and let's begin. 14 00:01:10,540 --> 00:01:13,540 So first of all, let's create employee class. 15 00:01:19,250 --> 00:01:25,640 Yeah, and in here, we're going to create a death unit method, which is the constructor, and we're 16 00:01:25,640 --> 00:01:34,730 going to pass variables, years of experience and we have position. 17 00:01:34,730 --> 00:01:36,470 Name, yeah. 18 00:01:38,770 --> 00:01:44,020 Name of employee, yeah, this is what we were asked to pass. 19 00:01:44,800 --> 00:01:46,810 I have a small error here, a typo. 20 00:01:50,870 --> 00:01:59,840 Yeah, this is what we were asked to pass, and that's also to create the properties with the self keyword, 21 00:02:00,590 --> 00:02:02,460 as we already familiar with. 22 00:02:02,480 --> 00:02:05,750 OK, just going to copy paste it to save some time. 23 00:02:05,900 --> 00:02:07,560 I advise you to do the same. 24 00:02:07,850 --> 00:02:10,790 OK, if you can save some time with copy paste, it's always good. 25 00:02:10,900 --> 00:02:17,750 OK, ok, so these are the three variables that are going to be passed from the instances that we're 26 00:02:17,750 --> 00:02:19,370 going to create in a few minutes. 27 00:02:19,640 --> 00:02:28,060 So I'm creating them pre passing them already for the parent class right here and now for the class. 28 00:02:28,070 --> 00:02:35,330 I'm just going to add basically my my strategy is to create an overall structure for the assignment, 29 00:02:36,380 --> 00:02:43,940 which means create the methods, leave them empty, then create an instance, and then starting to build 30 00:02:43,940 --> 00:02:51,080 up the content of the methods at the end, because it's the most hard part to create all the calculations 31 00:02:51,080 --> 00:02:51,740 and all of that. 32 00:02:51,950 --> 00:02:55,030 So I'm just going to create the overall structure of the assignment. 33 00:02:55,060 --> 00:03:00,440 OK, so we have in the parent calculate salary. 34 00:03:01,190 --> 00:03:01,610 Yeah. 35 00:03:03,350 --> 00:03:08,180 And we're going to leave a best argument here in order to avoid errors. 36 00:03:08,450 --> 00:03:15,630 And then we have a deaf candidate for bonus up. 37 00:03:18,450 --> 00:03:19,590 Also a typo. 38 00:03:21,890 --> 00:03:22,880 Yeah, like that. 39 00:03:24,660 --> 00:03:31,820 Bass, here we are finished now, let's create a class child class programer, 40 00:03:35,240 --> 00:03:44,230 and it will inherit employees methods and properties like that, and in here we need to create death 41 00:03:45,620 --> 00:03:46,240 in it. 42 00:03:46,670 --> 00:03:51,530 Yeah, and here also going to create years of experience. 43 00:03:51,530 --> 00:03:52,850 Also going to save some time. 44 00:03:52,850 --> 00:03:54,560 Just copy all of them. 45 00:03:54,560 --> 00:03:58,870 I'm not sure we're going to use all of them, but you can always delete them later on, right. 46 00:04:01,250 --> 00:04:02,930 And in here, also self. 47 00:04:09,320 --> 00:04:11,220 This is the first one sorry, my mistake. 48 00:04:12,080 --> 00:04:13,640 Second one is position name. 49 00:04:14,000 --> 00:04:20,390 Yeah, we're starting from the left to the right, as always, self and then name of employee. 50 00:04:21,950 --> 00:04:22,870 Yeah, we're done. 51 00:04:22,880 --> 00:04:27,880 OK, and now we're seeing a small we encountered a small issue here. 52 00:04:27,890 --> 00:04:30,140 I'm always aware of what's happening on the page. 53 00:04:30,140 --> 00:04:30,560 I'm here. 54 00:04:30,830 --> 00:04:35,510 You can see here the Brownlee's, your background that we already seen from the previous videos. 55 00:04:36,050 --> 00:04:39,170 We see some kind of resolution here with the lamp. 56 00:04:39,240 --> 00:04:42,470 Mistretta click it and you can see ad superclass call. 57 00:04:42,770 --> 00:04:50,480 So basically Patra tells us that we need to pass these variables, these properties actually from here 58 00:04:50,480 --> 00:04:51,500 into the parent. 59 00:04:51,680 --> 00:04:59,960 So I'm just going to click it bang and you can see it created automatically the super init line for 60 00:04:59,960 --> 00:05:03,260 me in order to pass all the variables from here to the parent. 61 00:05:03,470 --> 00:05:09,530 OK, so this is we can do it automatically or either to write it manually. 62 00:05:09,530 --> 00:05:10,040 It doesn't matter. 63 00:05:10,040 --> 00:05:12,110 It's the same same effect. 64 00:05:12,110 --> 00:05:22,130 OK, and also in the class programmer, we were asked to create a def print data method like that. 65 00:05:22,880 --> 00:05:24,330 Have indention problem here. 66 00:05:24,330 --> 00:05:25,700 Let's go backwards. 67 00:05:25,700 --> 00:05:26,060 Yeah. 68 00:05:27,500 --> 00:05:29,750 And here self. 69 00:05:29,750 --> 00:05:30,050 Yeah. 70 00:05:30,080 --> 00:05:31,070 Also pass. 71 00:05:31,730 --> 00:05:36,050 And now outside of these two classes, let's create instances of an object. 72 00:05:36,050 --> 00:05:40,250 We have junior python programmer 73 00:05:42,710 --> 00:05:46,780 and it will get the program which is the child obviously. 74 00:05:46,790 --> 00:05:54,800 OK, the child you can see also it's marked with the same background and it will get one year of experience. 75 00:05:54,800 --> 00:05:57,890 The name would be front end with an underscore. 76 00:05:58,310 --> 00:06:01,040 And the name is Joseph. 77 00:06:01,520 --> 00:06:01,880 Yeah. 78 00:06:05,130 --> 00:06:06,090 First instance. 79 00:06:08,680 --> 00:06:19,810 And we also have seen dev ops instance and also programer class, and we have here six years senior. 80 00:06:21,520 --> 00:06:26,130 Dev ops, yeah, and the name is Dan, right? 81 00:06:26,740 --> 00:06:35,470 So these are our two instances that we are needed to create and now let's start with the baby from the 82 00:06:35,470 --> 00:06:38,060 beginning and start building up these methods. 83 00:06:38,080 --> 00:06:38,470 All right. 84 00:06:39,730 --> 00:06:43,870 OK, so first of all, we need to create a base salary, right? 85 00:06:46,130 --> 00:06:56,000 This is the variable base salary, it was mentioned in the assignment and then calculated salary, which 86 00:06:56,000 --> 00:07:01,820 at the moment you can either put your zero or you can use the keyword none, which means it's nothing. 87 00:07:01,940 --> 00:07:02,330 Yeah. 88 00:07:02,820 --> 00:07:10,820 And then let's try let's now build up the if statements that we were asked to use. 89 00:07:10,970 --> 00:07:20,630 OK, so first one was using the self years of experience and setting it up to be larger than zero but 90 00:07:20,630 --> 00:07:21,650 smaller than two. 91 00:07:21,830 --> 00:07:30,590 But we'll try to make it one one statement instead of doing like years of experience, bigger than zero, 92 00:07:30,590 --> 00:07:38,120 and then using the end argument and then making it self use of experience, smaller or smaller than 93 00:07:38,120 --> 00:07:38,470 two. 94 00:07:39,020 --> 00:07:47,750 OK, so instead of using these two arguments with an end parameter, we'll try to make it one parameter 95 00:07:47,750 --> 00:07:50,420 to be more efficient like this. 96 00:07:51,960 --> 00:08:00,840 OK, yeah, so we can make it like this, yeah, so you can see here sell off years of experience, 97 00:08:00,840 --> 00:08:05,070 either bigger than zero or smaller than two or equals. 98 00:08:05,070 --> 00:08:07,470 To do so, we can make it at once. 99 00:08:07,680 --> 00:08:10,080 We can also make, for example. 100 00:08:14,430 --> 00:08:21,240 Like this, yeah, but it's much longer it's less efficient. 101 00:08:22,470 --> 00:08:26,510 OK, so you see it's longer than the one in line 12. 102 00:08:27,240 --> 00:08:28,410 So I'm going to use this one. 103 00:08:28,450 --> 00:08:28,760 Yeah. 104 00:08:29,550 --> 00:08:38,730 And here we going to set up a calculated salary equals to base salary plus one thousand five hundred, 105 00:08:38,940 --> 00:08:43,770 because the people that have between zero and two years of experience are going to have increase of 106 00:08:43,770 --> 00:08:49,500 one thousand five hundred in their income, in their calculated salary right now if. 107 00:08:51,650 --> 00:09:01,250 Yeah, just going to copy the statement and place here, the number two, yeah, and here at the place, 108 00:09:01,250 --> 00:09:11,330 the number five and this statement said that base salary will be increased by two thousand five hundred. 109 00:09:11,750 --> 00:09:18,070 And also we had Ayliffe self years of experience, bigger than five. 110 00:09:18,440 --> 00:09:18,910 Yeah. 111 00:09:19,040 --> 00:09:24,350 And then the calculated salary would be increased by three thousand five hundred. 112 00:09:24,950 --> 00:09:32,660 OK, and then we going to use the default exit point the else, OK, because we can get instead of number 113 00:09:32,660 --> 00:09:34,520 here from the instance. 114 00:09:34,520 --> 00:09:34,930 Yeah. 115 00:09:34,940 --> 00:09:37,730 From here we can get may be true. 116 00:09:37,980 --> 00:09:40,730 OK, like boolean variable by mistake. 117 00:09:41,090 --> 00:09:47,480 We can get it through here and then if the true gets up to here, so we're going to have some kind of 118 00:09:47,480 --> 00:09:49,430 error here because if we put else. 119 00:09:51,060 --> 00:09:55,020 And put some calculation here, so it's not it's not true. 120 00:09:55,050 --> 00:10:04,500 Yeah, because we did not get any any true any like correct variable inside the method, we get a false 121 00:10:04,500 --> 00:10:05,070 variable. 122 00:10:05,160 --> 00:10:06,420 We got a wrong variable. 123 00:10:06,600 --> 00:10:10,730 So we're not going to do some calculations if we got a wrong variable. 124 00:10:10,740 --> 00:10:11,090 Yeah. 125 00:10:12,330 --> 00:10:20,170 So the thing is, we're using this else as an exit point in order to state that wrong value inserted. 126 00:10:20,190 --> 00:10:20,490 Yeah. 127 00:10:20,640 --> 00:10:26,850 If we got years of experience, either neither of these numbers zero to two, two to five or larger 128 00:10:26,850 --> 00:10:31,280 than five, if we got like a true or false value or we had a string. 129 00:10:31,830 --> 00:10:33,570 So it's a wrong value inserted. 130 00:10:33,600 --> 00:10:35,070 OK, so we need to print it out. 131 00:10:35,070 --> 00:10:36,180 We need to state it right. 132 00:10:37,740 --> 00:10:47,490 All right, and now we're going also outside of the if statement, you can see that like now I'm inside 133 00:10:47,490 --> 00:10:52,250 the if else, but if I'm going back to here, I'm outside. 134 00:10:52,290 --> 00:11:05,260 If and here I'm going to bring the calculated salary is going to string formating percentage calculate 135 00:11:05,390 --> 00:11:06,030 that salary. 136 00:11:06,150 --> 00:11:13,500 And the reason I'm not using the self because it's not a property, just a simple variable created inside 137 00:11:13,500 --> 00:11:13,980 the method. 138 00:11:13,980 --> 00:11:15,250 So I don't need to self. 139 00:11:15,390 --> 00:11:18,450 OK, it's not something that I've received from here. 140 00:11:18,600 --> 00:11:21,350 Just created it locally inside the inside the method. 141 00:11:21,570 --> 00:11:22,850 So I don't need self here. 142 00:11:24,300 --> 00:11:31,480 And if you recall, we were asked to calculate the bonus using this number. 143 00:11:31,500 --> 00:11:34,650 OK, so this number needs to go from this method. 144 00:11:36,860 --> 00:11:37,880 Into this method. 145 00:11:39,250 --> 00:11:44,300 So in this method, we need to receive the calculated salary, we can give it any name. 146 00:11:44,320 --> 00:11:52,090 OK, I can give it the calculated salary just to make some difference, to show you that it's not have 147 00:11:52,090 --> 00:11:52,960 to be the same. 148 00:11:53,230 --> 00:11:57,770 But the name, OK, I mean, the name does not have to be the same. 149 00:11:57,790 --> 00:11:58,150 Yeah. 150 00:11:59,290 --> 00:12:05,550 And inside here, the candidates for bonus, we had several conditions. 151 00:12:05,830 --> 00:12:11,740 So first of all, salary with bonus would be first of all, none. 152 00:12:13,040 --> 00:12:17,530 And then we had if and just want to stop here for a second. 153 00:12:18,190 --> 00:12:23,320 You recall that the previous video I told you I told you that you had a hint. 154 00:12:23,320 --> 00:12:33,730 And I also read the hint that you can use if front end as such in self. 155 00:12:36,600 --> 00:12:37,540 Position, name. 156 00:12:37,590 --> 00:12:46,260 OK, you can use this if and then use here is substring, OK, use a substring and then ask if this 157 00:12:47,040 --> 00:12:50,310 appears in here. 158 00:12:50,340 --> 00:12:52,170 OK, they are both strings. 159 00:12:52,470 --> 00:13:00,040 So this is a test of Python to check whether this statement appears in this statement. 160 00:13:00,060 --> 00:13:01,530 So this is what we're going to check. 161 00:13:01,860 --> 00:13:12,300 And in here we going to check whether whether salary like the salary with bonus would be equal to the 162 00:13:12,300 --> 00:13:17,240 calculated salary that we received multiplied by zero point one. 163 00:13:17,520 --> 00:13:22,770 OK, because we want to increase the salary by one by zero point one. 164 00:13:23,670 --> 00:13:27,090 So we're going to take it and multiply it by zero point one. 165 00:13:27,240 --> 00:13:27,550 Yeah. 166 00:13:27,810 --> 00:13:33,750 So this means this value would be increased by zero point one and it will be sent to here. 167 00:13:34,620 --> 00:13:42,550 And the other type of bonus we had is self years of experience, bigger than two years. 168 00:13:42,570 --> 00:13:46,560 So anyone with more than two years of experience will also receive a bonus. 169 00:13:47,700 --> 00:13:49,950 So are you going to place it here? 170 00:13:50,190 --> 00:14:00,060 And the calculated salary multiplied by zero point to OK and then print the bonus. 171 00:14:01,480 --> 00:14:11,590 For the position is and here I'm going to state inside these brackets because we're going to pursue 172 00:14:11,590 --> 00:14:12,450 two variables. 173 00:14:12,730 --> 00:14:20,640 First one is self positioning, and the second one is salary with bonus. 174 00:14:21,070 --> 00:14:23,680 OK, so the bonus for the position. 175 00:14:24,960 --> 00:14:27,520 Is salary with bonus. 176 00:14:28,590 --> 00:14:31,500 OK, so we have completed this method as well. 177 00:14:32,580 --> 00:14:40,050 And what we are left to do is just to print out from the child, OK, you can you can see here that 178 00:14:40,050 --> 00:14:43,110 we up until now, we handled with these methods. 179 00:14:43,210 --> 00:14:50,240 They belong to the parent and we are left with this method with which belongs to the child. 180 00:14:50,580 --> 00:14:56,910 And right here, we were asked to print out a certain sentence that would include the position name 181 00:14:56,910 --> 00:14:58,380 and the salary with bonus. 182 00:14:59,130 --> 00:15:05,320 Yeah, the salary with know the name of employee and the positioning. 183 00:15:05,460 --> 00:15:06,180 My mistake. 184 00:15:06,500 --> 00:15:10,380 OK, so print the employee. 185 00:15:12,510 --> 00:15:13,410 Then its name. 186 00:15:14,990 --> 00:15:21,210 Works as a position name in our company. 187 00:15:21,460 --> 00:15:30,230 Yeah, and out here, percentage brackets, I don't have self name call myself. 188 00:15:31,480 --> 00:15:32,200 Positioning. 189 00:15:32,620 --> 00:15:41,410 All right, I think we're done off creating the content of all of the methods across the children and 190 00:15:41,410 --> 00:15:45,100 the parents, and now we're only left to execute. 191 00:15:49,830 --> 00:15:50,820 Off method's. 192 00:15:52,610 --> 00:15:57,770 Yeah, not executed to execute, yeah. 193 00:16:00,220 --> 00:16:10,880 So first one would be junior position programmer that calculate salary and by going up in here, OK, 194 00:16:12,730 --> 00:16:19,510 calculated salary, we were supposed to return the value out of this method, right. 195 00:16:20,530 --> 00:16:26,650 We're supposed to return this value and then use this value and inserted here. 196 00:16:28,530 --> 00:16:35,970 And we can achieve it by using the return key word and then calculate the salary, and that way we're 197 00:16:35,970 --> 00:16:41,190 basically taking what we have inside this calculated salary and send it. 198 00:16:42,750 --> 00:16:54,520 Send it outside of this statement here and we need to create a variable here, calculated salary value. 199 00:16:55,320 --> 00:17:02,580 Yeah, again, we can put any name here, but the meaning is that from here we're going to extract the 200 00:17:02,580 --> 00:17:05,890 calculated salary because we used every turn. 201 00:17:06,120 --> 00:17:13,590 OK, so once we use a return, this statement is going to have an output of a variable and we're going 202 00:17:13,590 --> 00:17:14,760 to place it here. 203 00:17:18,520 --> 00:17:27,670 And then we're going to use the junior python program, that bonus candidates for bonus and then this 204 00:17:27,670 --> 00:17:30,930 value, the calculated salary we're going to put inside it. 205 00:17:32,320 --> 00:17:32,770 OK. 206 00:17:34,530 --> 00:17:35,010 This one. 207 00:17:36,360 --> 00:17:38,820 Then we're going to use it to calculate the bonus. 208 00:17:40,590 --> 00:17:50,610 All right, and then we're left with the sprint data, also with junior, junior python programmer doctoring 209 00:17:50,610 --> 00:17:53,340 data and we are done. 210 00:17:54,790 --> 00:17:55,380 All right. 211 00:17:55,650 --> 00:18:02,760 Just going to copy all these three or basically all these with the notes based them here. 212 00:18:04,460 --> 00:18:11,750 Copy the name of the instance and then you can see all the march here, one, two, three, I'm going 213 00:18:11,750 --> 00:18:17,030 to replace them with senior dev ops, OK, because it's basically the same. 214 00:18:17,030 --> 00:18:19,850 We're executing this method, this method and this method. 215 00:18:20,450 --> 00:18:25,100 And the difference is just we're trying to execute it now with this instance. 216 00:18:25,400 --> 00:18:27,080 OK, so I'm thinking. 217 00:18:27,710 --> 00:18:28,550 Based here. 218 00:18:29,660 --> 00:18:30,440 Based here. 219 00:18:31,400 --> 00:18:32,120 Based here. 220 00:18:32,750 --> 00:18:33,140 Done. 221 00:18:35,560 --> 00:18:37,810 OK, let's try to run it. 222 00:18:41,700 --> 00:18:46,890 All right, we have like a mix up of printouts here, so I'm just going to add here, print special 223 00:18:46,890 --> 00:18:49,800 keywords again to separate the print. 224 00:18:51,600 --> 00:18:52,410 So that's it. 225 00:18:52,440 --> 00:18:54,870 OK, we I have a correct answers here. 226 00:18:54,870 --> 00:18:56,910 We have calculations for front end. 227 00:18:57,960 --> 00:19:07,170 We have first of all, we have this salary, which is addition of one thousand five hundred to the front 228 00:19:07,170 --> 00:19:10,430 end because he has between zero and two years of experience. 229 00:19:10,440 --> 00:19:11,220 The front end. 230 00:19:11,280 --> 00:19:15,130 Yeah, he has won every year of experience. 231 00:19:15,130 --> 00:19:19,200 There is going to be added 1500 to the salary. 232 00:19:19,380 --> 00:19:20,790 So this value is correct. 233 00:19:22,140 --> 00:19:29,190 Then once we have four thousand, we're passing this variable to here and then in here he's a front 234 00:19:29,190 --> 00:19:29,540 end. 235 00:19:29,730 --> 00:19:37,770 So once we multiply 4000 by one point one, we're getting four thousand five hundred. 236 00:19:38,100 --> 00:19:40,910 OK, so this is the printout that we're getting here. 237 00:19:41,310 --> 00:19:44,040 So we got the correct answer is here as well. 238 00:19:44,200 --> 00:19:47,820 And also the last print data. 239 00:19:48,240 --> 00:19:51,420 The employee, Joseph, works as a frontyard in our company also. 240 00:19:51,420 --> 00:19:51,930 Correct. 241 00:19:53,760 --> 00:19:59,610 Then we have the dev ops and also executed for the same methods. 242 00:20:00,390 --> 00:20:06,780 So first of all, we have his salary, which is increased because he has six years. 243 00:20:07,530 --> 00:20:09,050 So let's go up in here. 244 00:20:09,420 --> 00:20:11,670 So he goes to this category here. 245 00:20:12,030 --> 00:20:19,650 So he has two thousand five hundred plus three thousand five hundred equals to six thousand, which 246 00:20:19,650 --> 00:20:20,340 is correct. 247 00:20:21,450 --> 00:20:29,160 And then this calculated salary is returned and is certainty here and in here we can see he has more 248 00:20:29,160 --> 00:20:30,470 than two years of experience. 249 00:20:30,840 --> 00:20:38,400 So we are going to take the calculated and multiplied by one point two, which equals to seven thousand 250 00:20:38,400 --> 00:20:39,150 two hundred. 251 00:20:39,270 --> 00:20:42,640 You can check it yourself, which is also the correct answer. 252 00:20:42,960 --> 00:20:48,720 And last but not least, we have the printout and data, which is the employee. 253 00:20:48,720 --> 00:20:50,980 Dan works as a senior officer in our company. 254 00:20:52,530 --> 00:21:00,360 OK, I think this concludes our part in practicing inheritance in OLP in Python was challenging. 255 00:21:00,360 --> 00:21:01,710 It was not easy. 256 00:21:01,860 --> 00:21:06,030 But I'm sure that if some of you completed it successfully, it's great. 257 00:21:06,270 --> 00:21:10,860 Even partial resolutions are also great because it's not easy, as I just said. 258 00:21:11,460 --> 00:21:16,470 And I highly recommend you to use the attachment file of the code that I wrote here. 259 00:21:17,010 --> 00:21:23,940 It's attached to the lecture and to paste it into your python, into your picture and to do some experiments 260 00:21:23,940 --> 00:21:26,010 in to compare it with your resolution. 261 00:21:26,190 --> 00:21:32,720 And if you had some errors to check what you did wrong, it's really recommended to do experiments. 262 00:21:33,210 --> 00:21:37,620 This is my preferred way of of learning new things. 263 00:21:38,550 --> 00:21:39,000 All right. 264 00:21:39,240 --> 00:21:41,120 We have completed this lecture. 265 00:21:41,370 --> 00:21:48,210 Finally, we are familiar with practicing of inheritance in Python as well. 266 00:21:48,390 --> 00:21:50,120 And I will see you in the next video. 267 00:21:50,130 --> 00:21:50,640 Thank you.