Hi there.
All right, so I think it's time to see the resolution for the homework assignments regarding objects.
OK, so once you open your chance, create a new module and then we'll start off with showing on the
answers.
OK, so basically what we need to create here is a class.
All right.
And the name of the class would be car.
And then we have the Init method, which is identified, first of all, with a key word def.
Then you have double on the score in it, double under score, and then the self is either completed
automatically.
And then we're going to receive one argument here, which is car data list as asked in the assignment.
And here we're going to have the self parameter and then we have car data list.
OK, same as we declared it one line above and like that.
OK, so basically what we have here is the Init method.
It receives this list and it's converted here into a property of an object of a future object as we're
going to create now.
OK, now we're going to create the classes methods.
OK, first of all, we have insurance calculation.
All right.
And we're going to leave it empty for a second.
And we have their doors closed method, which would tell us whether the doors are closed or not.
We're going to leave them empty for a few moments.
And then we have also def get car data.
All right.
So these are the classes methods.
OK, and then we were asked to create two lists for first.
One is least offered and we have four, the focus list and then we have year of release, current Price
and Ford Focus, which is the name of the car.
The last one is the status of the doors.
OK, also we're going to create an instance of an object which will belong to the car class.
OK, Ford Focus, for instance, and it's going to belong to the car class.
And here we go into place or basically, in other words, to pass this list inside.
So what we completed this at this point is we created a list here.
We passed the list into the instance, OK, to this instance for focus.
And this list was went up inside into the Init method and up in here and then here.
And then it can be used in each of these methods right here.
All right.
And we can create an additional an additional list for Audi three.
This is an instance of Ford Focus.
Right.
And we can create an additional list off the list of ality.
OK, just make it a capital here.
And we have Audi A3 list.
And in here we have what do we have here, we have 2011, 15 thousand Audi A3
and then we have a false for the Dumbledore's status and the same, we're going to create instant's.
Of Audi A3 and we have Audi A3 instance
and I'm sorry, and then like that, and also it belongs to car and we're going to pass this list inside
this instance right here, OK?
So wherever we're going to initiate this instance, this list would come in use and these methods.
And once we once we take this instance and we take this one into use.
So this list would come into use in this method as well.
OK, so we came up with the framework, you might say, for that class instances and the list, which
is the arguments which are passed into the instance.
OK, and now let's go back to the top right here and start making calculations as we expected.
All right.
So first of all, we have self car data and this is our list, OK, so we can extract values out of
our list.
Once we mention self that car, there is a list, index zero.
So if we are using this instance, OK, so we're going to use two thousand five.
And if we are using this instance, sorry, if we're using this instance.
Yeah, we're going to get 2005.
And we if you are using this instance, we're going to get two thousand twenty eleven.
All right.
So we can basically pull out or extract values out of the past list which were passed into the instance
of an object.
Right.
But the developer that will come after after us and we'll read our code will not specifically understand
what this means.
And he will need to go backwards compatibility and see like what this thing means.
And he will need to go over here and then back here and see what this thing means and this thing means.
All right.
So we want our co-workers life to be easier.
And for that, we can create the following thing.
We can create appropriate variables as such and assign these values that value to the variable.
And that way it's more much more readable.
All right.
So we have car price, which is self car.
They the list index one.
And we also have the model that is self car.
The list to OK, so we have index one, which is car price.
You can see it right here, car price.
And you have the model which is index two and you can see it here and here.
OK, and these two lists, this one and this one passed into the instance.
Right.
So we have these variables for our disposal and now we can start calculating.
OK, so the assignment said that if the year off.
Year of release is small or equals 2020, but from the other hand, it's also OK, it's and year of
release is bigger or equals from 2010, right.
So we have this statement right here.
Basically, what we are saying is if the year is smaller than 2000 is in 20, but I'll have a mistake
here, but bigger than 2010.
And we also need to take into consideration the car price, which will get to it in a second.
But you can see here it continues yellow line below the statement that I mentioned here and say that
if and if we just click it and hover, then you can see that Pichon tries to tell something which is
very smart and tries to teach us stuff all the time.
So you can see simplify chain comparison.
Basically, pie chart tells us that we can simplify the statement and I'm going to use it.
You see here the yellow light just going to click it and then simplify chain comparison.
Then once clicking it, boom.
OK, I can see that the comparison statement is shortened and it's much more simplified.
You can see.
No, and then the comparison and then you can see the value.
And it's basically one long statement, but it's much shorter than what we have with the end operator
and this is much easier to understand.
OK, so looking at the assignment, we need also to take into consideration the car price and basically
we're going to do the same thing.
We're going to compare the car price, which should be bigger or equal to six thousand.
But from the other hand, it should be smaller than seventeen thousand like this.
And then we're going to create a new variable and you can call it calculated insurance.
And we were told that the car price multiplied by five percent.
All right, this would be the calculated insurance, OK?
So this way.
Just a second.
Like this, OK, so if the rear of the car is between 2000 and 2020 and the car price is to be between
six and seven, 17 K, so the insurance price should be five percent out of the car's price like this.
So this is the insurance price and all other options else.
The calculated insurance would be car price multiplied by zero zero seven, which is seven percent of
the car price.
And what I would like to do now is also to print the insurance calculated.
Insurance.
Is and we're going to use string formatting here, so we're going to use the percentage and then after
closing the quotation mark, we're going to put additional percentage and then the calculated variable
and then it will be put out from here into here.
All right.
So we finished this method, completely done with it.
OK, and now we can go over to the next method.
We can also use, like calculate the insurance price is calculate the insurance price.
For the model.
OK, so I'm just going to mention here the name of the model, and because we're going to have two variables
mentioned here in the print, so we need to have round the brackets here, OK?
So that way we can put divided by a comma self.
We don't need the self because it's a local variable model like this.
So then this variable will be put out here and this variable would go up in here.
So I think we're good with this method.
We are done with it.
All right.
And then we're going to discuss now of doors closed method.
And in here, things are pretty simple.
We have those those status, which is a new variable, and we are going to pull out the last value out
of the list.
OK, so we have this list and this list and these both lists are passed into the unit method.
So we're going to use the list, OK, from here.
And you can see by going backwards up to the list, the original list that you can see, the last variable
in both lists indicates the door status in the cards.
So we can either mention here index zero.
One, two, three.
Right.
You can either put here and the number three, we can either mention minus one, if you recall, it
means that we're going to extract the best value out of the list.
OK, so this is Dorje status.
And then if Dorje status equals equals true.
Yeah.
Then print doors are closed.
OK, and then if you know what, let's start off with alse Dawes status falls and then we can put doors
are open.
Right.
Well partially.
Partially this answer is correct.
Just a moment.
I don't need it.
OK, sorry about that.
So, like, OK, this statement is is actually partially correct, because basically what I did here
is saying that if I had a true OK, if I had a true inside this cell.
So doors are closed and our doors are open, basically it sounds right, but it's not completely right.
OK, because think of the third option.
If here I'm going to put B, C, OK, not boolean variable, true or false, and God is going to put
a wrong value.
ABC and considering this ABC here, once we were going to execute this method.
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
false false argument here.
So that will be completely wrong.
So in order to fix this situation of getting false values here and false printouts, we're going to
do small change.
Right.
So are going to do alif door status false.
And then we're going to have those are open, OK?
And then we're going to have alse and we're going to print wrong value incertain.
All right.
So in this case, once we have ABC and gets up in here, so we're going to check whether it's true,
whether it's false and if it's neither of them is going to go up to down to the house and print out
wrong value, insert it.
OK, this is the most correct answer.
And also, if you're going to be asked in interviews, which I'm sure you're going to be asked about,
like to write some kind of, if else statement, make sure that you cover all options and not just most
options, because if you want to be accepted into a certain position, you need to be accurate.
All right.
So this is an accurate answer.
OK, so let's erase it and put through here again, as it was before.
So we already covered this method as well.
And now I'm just going to print out the car model is percentage as it was released and the year.
OK, I'm not sure that I'm correct regarding all the like, commas here and all that, but I guess this
is the the hang of the assignment of the printout just to use variables and use string formatting on
a couple of variables.
All right.
So I'm just don't remember the accurate sentences I asked you to print.
OK, but I guess it's something like that, OK.
And the year percentage.
Yes.
And it costs.
Percentages and then outside of quotation marks percentage.
Brackets, and then we have self.
This time, I'm going to have the lazy answer, just going to use that the sales of the of the list
without setting up appropriate variables, but it's also the same.
Just want you to see several types of approaches for each answer, OK, for each method so you can see
here self khaleda one.
OK, so let's go over what I wrote here.
All right.
So the car model is OK, we have index to 012.
So the car, the car model is for focus.
For example, it was released that the year off in zero was released at the end of 2005 and it costs.
Five thousand.
So I think we're good here as well.
OK, so we have completed all the methods, content.
And now let's let's, uh, let's try to execute the methods, because here the bottom part, which is
outside of the glass we just declared, list an instance of an object.
But we did not mention the execution of these methods using these instances.
Right.
So let's do it right now.
OK, so execute methods for Audi, not out its Ford Focus instance.
So we have Ford Focus, for instance.
That first one is what, insurance calculation?
OK, and then we have Ford Focus instance and we have doors closed.
Yeah.
And the last one is Ford Focus and we have great car data.
OK, then in between before printing printing out Audi outis execution of methods, I'm going to use
the special keyword which is slash.
And so the printouts will be divided so it won't get mixed up.
OK, so in here we're going to execute.
Methods, oops, methods for four for Audi A3.
Right, so just going to copy all of this and just change the name of the instance for Audi three one
to three.
And we are done.
OK, now let's try to run it and pray that everything's going to be fine.
Where is it?
Car practice answers right here.
All right, so there you have it, so calculated, an insurance price for Ford Motor four for the model
for Focus is three hundred fifty doors are closed because they are closed.
It's true.
The car model is for focus.
It was released for Gothia, a D.
Let me just run it again, OK?
It was released at the year 2005, and it cost 5000, which is correct, and calculation for the insurance
for all the eight three.
Seven hundred fifty doors are open.
OK, because the status of the doors is false.
It means they are open.
And the car model is Audi three.
It was released at the year of 2011.
And it cost two thousand.
It costs fifteen thousand.
So there you have it.
You have coverage of creating a class, OK, creating an init method, using methods of a class.
All right.
Farseeing an argument which is a list into the math, into the instance of an object creating an instance
of an object and executing the methods.
So we basically covered all topics related to creation of an object and using all of its features.
And I think it covers this topic pretty much completely.
I will see you in the next videos and we'll discuss further about object oriented programming.
Thank you and bye bye.