Hi, everybody, I'm very happy that you're here with me.
We will try to resolve and get the answers of inheritance homework assignment.
I guess it was a bit challenging than previous assignments you can compare it to may be assignments
or variables or collections.
So obviously these assignments now are much harder and much more challenging, but there are surely
doable because we went over all the topics in the previous lectures.
OK, so quick overview of what do we need to do?
We need to create two classes.
One of them is the parent employee.
The other one is the programmer, which is the child.
We need to make inheritance between child and parent.
And we also need to create some calculations, methods and also to bring some values.
So once you open by charm, create a new file of OAP inheritance practice and let's begin.
So first of all, let's create employee class.
Yeah, and in here, we're going to create a death unit method, which is the constructor, and we're
going to pass variables, years of experience and we have position.
Name, yeah.
Name of employee, yeah, this is what we were asked to pass.
I have a small error here, a typo.
Yeah, this is what we were asked to pass, and that's also to create the properties with the self keyword,
as we already familiar with.
OK, just going to copy paste it to save some time.
I advise you to do the same.
OK, if you can save some time with copy paste, it's always good.
OK, ok, so these are the three variables that are going to be passed from the instances that we're
going to create in a few minutes.
So I'm creating them pre passing them already for the parent class right here and now for the class.
I'm just going to add basically my my strategy is to create an overall structure for the assignment,
which means create the methods, leave them empty, then create an instance, and then starting to build
up the content of the methods at the end, because it's the most hard part to create all the calculations
and all of that.
So I'm just going to create the overall structure of the assignment.
OK, so we have in the parent calculate salary.
Yeah.
And we're going to leave a best argument here in order to avoid errors.
And then we have a deaf candidate for bonus up.
Also a typo.
Yeah, like that.
Bass, here we are finished now, let's create a class child class programer,
and it will inherit employees methods and properties like that, and in here we need to create death
in it.
Yeah, and here also going to create years of experience.
Also going to save some time.
Just copy all of them.
I'm not sure we're going to use all of them, but you can always delete them later on, right.
And in here, also self.
This is the first one sorry, my mistake.
Second one is position name.
Yeah, we're starting from the left to the right, as always, self and then name of employee.
Yeah, we're done.
OK, and now we're seeing a small we encountered a small issue here.
I'm always aware of what's happening on the page.
I'm here.
You can see here the Brownlee's, your background that we already seen from the previous videos.
We see some kind of resolution here with the lamp.
Mistretta click it and you can see ad superclass call.
So basically Patra tells us that we need to pass these variables, these properties actually from here
into the parent.
So I'm just going to click it bang and you can see it created automatically the super init line for
me in order to pass all the variables from here to the parent.
OK, so this is we can do it automatically or either to write it manually.
It doesn't matter.
It's the same same effect.
OK, and also in the class programmer, we were asked to create a def print data method like that.
Have indention problem here.
Let's go backwards.
Yeah.
And here self.
Yeah.
Also pass.
And now outside of these two classes, let's create instances of an object.
We have junior python programmer
and it will get the program which is the child obviously.
OK, the child you can see also it's marked with the same background and it will get one year of experience.
The name would be front end with an underscore.
And the name is Joseph.
Yeah.
First instance.
And we also have seen dev ops instance and also programer class, and we have here six years senior.
Dev ops, yeah, and the name is Dan, right?
So these are our two instances that we are needed to create and now let's start with the baby from the
beginning and start building up these methods.
All right.
OK, so first of all, we need to create a base salary, right?
This is the variable base salary, it was mentioned in the assignment and then calculated salary, which
at the moment you can either put your zero or you can use the keyword none, which means it's nothing.
Yeah.
And then let's try let's now build up the if statements that we were asked to use.
OK, so first one was using the self years of experience and setting it up to be larger than zero but
smaller than two.
But we'll try to make it one one statement instead of doing like years of experience, bigger than zero,
and then using the end argument and then making it self use of experience, smaller or smaller than
two.
OK, so instead of using these two arguments with an end parameter, we'll try to make it one parameter
to be more efficient like this.
OK, yeah, so we can make it like this, yeah, so you can see here sell off years of experience,
either bigger than zero or smaller than two or equals.
To do so, we can make it at once.
We can also make, for example.
Like this, yeah, but it's much longer it's less efficient.
OK, so you see it's longer than the one in line 12.
So I'm going to use this one.
Yeah.
And here we going to set up a calculated salary equals to base salary plus one thousand five hundred,
because the people that have between zero and two years of experience are going to have increase of
one thousand five hundred in their income, in their calculated salary right now if.
Yeah, just going to copy the statement and place here, the number two, yeah, and here at the place,
the number five and this statement said that base salary will be increased by two thousand five hundred.
And also we had Ayliffe self years of experience, bigger than five.
Yeah.
And then the calculated salary would be increased by three thousand five hundred.
OK, and then we going to use the default exit point the else, OK, because we can get instead of number
here from the instance.
Yeah.
From here we can get may be true.
OK, like boolean variable by mistake.
We can get it through here and then if the true gets up to here, so we're going to have some kind of
error here because if we put else.
And put some calculation here, so it's not it's not true.
Yeah, because we did not get any any true any like correct variable inside the method, we get a false
variable.
We got a wrong variable.
So we're not going to do some calculations if we got a wrong variable.
Yeah.
So the thing is, we're using this else as an exit point in order to state that wrong value inserted.
Yeah.
If we got years of experience, either neither of these numbers zero to two, two to five or larger
than five, if we got like a true or false value or we had a string.
So it's a wrong value inserted.
OK, so we need to print it out.
We need to state it right.
All right, and now we're going also outside of the if statement, you can see that like now I'm inside
the if else, but if I'm going back to here, I'm outside.
If and here I'm going to bring the calculated salary is going to string formating percentage calculate
that salary.
And the reason I'm not using the self because it's not a property, just a simple variable created inside
the method.
So I don't need to self.
OK, it's not something that I've received from here.
Just created it locally inside the inside the method.
So I don't need self here.
And if you recall, we were asked to calculate the bonus using this number.
OK, so this number needs to go from this method.
Into this method.
So in this method, we need to receive the calculated salary, we can give it any name.
OK, I can give it the calculated salary just to make some difference, to show you that it's not have
to be the same.
But the name, OK, I mean, the name does not have to be the same.
Yeah.
And inside here, the candidates for bonus, we had several conditions.
So first of all, salary with bonus would be first of all, none.
And then we had if and just want to stop here for a second.
You recall that the previous video I told you I told you that you had a hint.
And I also read the hint that you can use if front end as such in self.
Position, name.
OK, you can use this if and then use here is substring, OK, use a substring and then ask if this
appears in here.
OK, they are both strings.
So this is a test of Python to check whether this statement appears in this statement.
So this is what we're going to check.
And in here we going to check whether whether salary like the salary with bonus would be equal to the
calculated salary that we received multiplied by zero point one.
OK, because we want to increase the salary by one by zero point one.
So we're going to take it and multiply it by zero point one.
Yeah.
So this means this value would be increased by zero point one and it will be sent to here.
And the other type of bonus we had is self years of experience, bigger than two years.
So anyone with more than two years of experience will also receive a bonus.
So are you going to place it here?
And the calculated salary multiplied by zero point to OK and then print the bonus.
For the position is and here I'm going to state inside these brackets because we're going to pursue
two variables.
First one is self positioning, and the second one is salary with bonus.
OK, so the bonus for the position.
Is salary with bonus.
OK, so we have completed this method as well.
And what we are left to do is just to print out from the child, OK, you can you can see here that
we up until now, we handled with these methods.
They belong to the parent and we are left with this method with which belongs to the child.
And right here, we were asked to print out a certain sentence that would include the position name
and the salary with bonus.
Yeah, the salary with know the name of employee and the positioning.
My mistake.
OK, so print the employee.
Then its name.
Works as a position name in our company.
Yeah, and out here, percentage brackets, I don't have self name call myself.
Positioning.
All right, I think we're done off creating the content of all of the methods across the children and
the parents, and now we're only left to execute.
Off method's.
Yeah, not executed to execute, yeah.
So first one would be junior position programmer that calculate salary and by going up in here, OK,
calculated salary, we were supposed to return the value out of this method, right.
We're supposed to return this value and then use this value and inserted here.
And we can achieve it by using the return key word and then calculate the salary, and that way we're
basically taking what we have inside this calculated salary and send it.
Send it outside of this statement here and we need to create a variable here, calculated salary value.
Yeah, again, we can put any name here, but the meaning is that from here we're going to extract the
calculated salary because we used every turn.
OK, so once we use a return, this statement is going to have an output of a variable and we're going
to place it here.
And then we're going to use the junior python program, that bonus candidates for bonus and then this
value, the calculated salary we're going to put inside it.
OK.
This one.
Then we're going to use it to calculate the bonus.
All right, and then we're left with the sprint data, also with junior, junior python programmer doctoring
data and we are done.
All right.
Just going to copy all these three or basically all these with the notes based them here.
Copy the name of the instance and then you can see all the march here, one, two, three, I'm going
to replace them with senior dev ops, OK, because it's basically the same.
We're executing this method, this method and this method.
And the difference is just we're trying to execute it now with this instance.
OK, so I'm thinking.
Based here.
Done.
OK, let's try to run it.
All right, we have like a mix up of printouts here, so I'm just going to add here, print special
keywords again to separate the print.
So that's it.
OK, we I have a correct answers here.
We have calculations for front end.
We have first of all, we have this salary, which is addition of one thousand five hundred to the front
end because he has between zero and two years of experience.
The front end.
Yeah, he has won every year of experience.
There is going to be added 1500 to the salary.
So this value is correct.
Then once we have four thousand, we're passing this variable to here and then in here he's a front
end.
So once we multiply 4000 by one point one, we're getting four thousand five hundred.
OK, so this is the printout that we're getting here.
So we got the correct answer is here as well.
And also the last print data.
The employee, Joseph, works as a frontyard in our company also.
Correct.
Then we have the dev ops and also executed for the same methods.
So first of all, we have his salary, which is increased because he has six years.
So let's go up in here.
So he goes to this category here.
So he has two thousand five hundred plus three thousand five hundred equals to six thousand, which
is correct.
And then this calculated salary is returned and is certainty here and in here we can see he has more
than two years of experience.
So we are going to take the calculated and multiplied by one point two, which equals to seven thousand
two hundred.
You can check it yourself, which is also the correct answer.
And last but not least, we have the printout and data, which is the employee.
Dan works as a senior officer in our company.
OK, I think this concludes our part in practicing inheritance in OLP in Python was challenging.
It was not easy.
But I'm sure that if some of you completed it successfully, it's great.
Even partial resolutions are also great because it's not easy, as I just said.
And I highly recommend you to use the attachment file of the code that I wrote here.
It's attached to the lecture and to paste it into your python, into your picture and to do some experiments
in to compare it with your resolution.
And if you had some errors to check what you did wrong, it's really recommended to do experiments.
This is my preferred way of of learning new things.
All right.
We have completed this lecture.
Finally, we are familiar with practicing of inheritance in Python as well.
And I will see you in the next video.
Thank you.