Hey, welcome back.
So, so far we have the main loop or both.
Our methods are basically empty.
So in this video, we want to code the methods.
Let's do some housekeeping.
First.
Punch arm is telling us that we need one more break line in here because we need to break lines around
class definitions to be in line with the PEP eight guide.
Also, the idea here, this is a built in name.
So in that case, it's a good idea to have another name for this.
For example, hotel ID since ID is an occupied name in Python.
So same goes for here.
Hotel ID.
So this is different from this, by the way.
So we will get the hotel ID from here and we'll pass it here.
So this year it should also be hotel ID.
And.
Yeah.
So that's fine.
Now let's populate the methods with code.
To do that, we want to refer to the main loop again.
So we want to follow the order of the main loop.
So let's see what we've got here.
We print out the DF.
That's fine.
We're not interacting with our classes here yet, and then we get the ID from the user and here we create
a hotel instance with the hotel ID, right?
So the user will enter perhaps one of these IDs.
Here, let's say 134.
So hotel.
So then 134 will go in here.
And then we check if the hotel is available.
Right.
So this methods here now.
We'll do something like a that is the case.
Return true.
Else return false.
So if the hotel.
Where the F?
It is equal to that hotel it.
But see that if we just do hotel ID here, this will not be recognized because this is a local variable
of the init method.
Right.
So this doesn't recognize that.
And pa char will underline this in red.
It doesn't do it because we have another global variable in here.
So if we change this hotel ID here to something else like hotel ID with capital IE and capital D this
as well.
So now this is a different name from this and now this is underlined in red.
Parcham is complaining that, oh, this reference is not resolved.
It has not been defined because it's part of this method only.
So what we can do is we can say self that hotel ID, so this one is equal to hotel ID and then here
we say self that hotel ID in this case this will be fine.
So again, the flow is this.
The user enters a hotel ID here and this goes in here.
So 134 And then from here this will go.
In here.
And then from here.
It will go and be assigned to this self that hotel ID so self that hotel ID will be equal to 134.
Right.
And then here we check.
Give me the available
field.
So which corresponds to this.
Let me split it to the right in here.
So we want the available value, which could be.
Yes, or it could be no with that expression.
Actually, we do this.
We do this before in here, and then we say, let's say.
We saw that in variable rate availability and then we say if availability
is equal to yes, then we return true rates.
I have a typo here.
And so let me explain you this expression first.
What this is.
Well, this is the equivalent of saying that, oh, import pandas and then create a pandas dataframe.
Right.
And then let's suppose that hotel ID is 134.
Write one of these.
This first hotel.
Avenge this expression here.
Let me remove self, because for now in this session we have hotel ID we don't have it as self that
hotel ID.
So
availability now is equal to yes.
So the variable is equal to yes.
And actually we also need to apply a squeeze methods here to get the actual
string only because this will give us like a series.
We worked with pandas before in the course, so you should be able to tell the difference between this
and that.
So this is a string and this is what we want.
So let's add a squeeze method as well in here.
So if availability is equal to yes, we return true, otherwise we return false.
So in that case, if hotel available, it means that if available returns true, then we book the hotel,
which we instantiate it in here.
So now we go to the book method.
And see what we can do in here.
So what should the book method do?
Well, the available methods.
Checks.
If the hotel.
It's available.
The book methods.
Books.
A hotel hotel by changing its availability to.
No.
So from yes, we want to change that, to know so that if the hotel is booked, it shouldn't be available
anymore.
Of course, these would have other variables such as the dates and so on.
But let's not go into those details, focus on object oriented programming.
So the case with this would be this expression here.
So put that in there.
So that gives us that row, that particular cell.
And we want to re assign that to know.
And after that, we want to say DF dot to CSV because we want to update the actual file on disk.
Right?
So far, we're just in the data frame in the Python session, but we want to save the changes to the
CSV file.
So use the same name hotels that CSV to override that existing file and also use index equal to false
so that python doesn't add another index.
So that Python doesn't add another column index to the CSV file.
So that is what the available methods should do.
It should return true or false, and that is what the book method should do.
So with that.
We have gone up to this point in here.
Right.
And before we go further with the other methods, let's check if we're doing things correctly in here.
So let me run this program.
Right.
And you should get the list of hotels from this line as a data frame.
And then you should get the enter the idea of the hotel from this line.
So let's enter an ID.
The answer, an idea which has the available fields equal to yes.
If you don't have that, you can always change this manually, this CSV file.
You can just write this.
If it was no, you can write this to yes, save the file and so on.
So I'm going to choose 134 press enter.
We got an error.
The problem here is that this input function, as you know, gives you always strings.
So even if you enter 134, that will be treated as a string.
So hotel ID will be equal to a string.
And the problem with that is that when we check that string against the data frame value, the data
frame value for the ID is a an integer.
So that means the dataframe value, the actual value in here.
134 will not be equal to our string.
To fix that, you want to go to hotels dot cs V and add a D type is equal to string SDR, so that will
load all the values as strings, even the numbers.
134 188 655 and so on.
The problem with that is that the capacities will be treated also as strings, which could be a problem.
So a better solution would be to specify only the dataframe columns which you want to be treated as
string.
So the idea in this case, so that could be supplied as a dictionary like that.
So I'd here make sure that your column is also named ID ID here, ID there.
Let's run the program again.
So one, two, three, four.
Press enter.
Enter your name, audit and yep, no errors.
This time you can check hotels at CSV and you'll see that my value in the available fields was changed
to no.
So things are working fine.
The hotel was booked, it's not available anymore.
And now the next step is to print out a ticket for the user.
So we need to implement the methods of the reservation tickets class.
Let's do that in the next video.
Thanks.