Hey, welcome back.
We have been using this example with the client and the barista where the client orders a coffee to
the barista and the barista prepares the coffee.
So when the client says coffee, that is the inputs.
The process of coffee making is the function.
But sometimes the client could say more than coffee.
They could also say milk or sugar.
So what they're doing is they are providing multiple arguments, multiple inputs.
And the function the process will.
Consider all these arguments during the process so that the product is a result of all these arguments.
So the interaction between these arguments.
So the same works with Python.
This function here gets only one argument file path, but it could happen that the function needs more
than one arguments.
However this particular function.
Doesn't really need more than one arguments.
So the only changing factor here could be the five path.
That's why this has to come from the outside.
Therefore, we will not add multiple arguments to this function.
But we have something else here.
We still have some repetitive code when we write the file.
So.
We have one here in edit.
We have these lines, the same ones under AD and what else do we have?
We also have a third.
Instance of those two lines under complete.
So what I'll do now first is create another function.
So define.
Let's name this right to choose.
So that's what this function will do.
For us.
This function gives us a to do this function writes it to those in the file.
And here we're going to place these two lines.
And now let's think, what does this function want to know from us?
From.
The entity that calls it.
So the entity is we could say the entity here is this ad case, the ad condition.
And in this block of codes, this call to that function.
So what kind of information should we send from this place to the function?
You could also say that this if conditional block is the client that uses the function.
So there are different parts in the program, different entities, right.
So think of the program as the cafe and the client is here who uses that function.
And the function is the process, the making of coffee and so on.
So the program is the cafe where everything happens.
So for this function to be able to write to dos in the text file, it needs to know two things.
It needs to know the file path, and it needs to know what to write in that file.
In this case is the two twos.
So these are local variables.
Therefore.
It's a good idea to have different names from this.
So that's and that is not the same variable.
As I explained previously, that is a global variable.
That is a local variable.
So to be more clear, let's say to dos arc for argument, So that will be the argument.
And then you replace the literal string with wild Path.
And to those with tattoos underscore Eric.
And then replace these two lines with right to this.
To use the text and comma to dos.
I didn't assign it to a variable.
I'll explain you why.
Exactly.
And also, we didn't return anything in here.
Why?
Well, because.
This function is more like a procedure.
It doesn't return anything, so it modifies some components in this file.
In this case, it modifies the file, the text file, but it doesn't need to return anything.
We don't need any value from this function.
This function just has to go somewhere.
Do that, and that's it.
So that was different from this function which returns something and we captured that return in the
variable here to dos equal to get to dos.
And with this function, write to dos.
Since it doesn't return anything we don't need, we have.
We have nothing to capture.
And as I mentioned, this function actually returns a non object, which is useless.
So if you did see our variable equal to that variable would be getting the non value, which as I said
is is useless.
So this function, the role of this function is to behave as a procedure.
So what happens is that again, the interpreter will read these the syntax of these lines, and if the
syntax is okay, then it carries on for the other line.
So then it executes to this line, executes that it actually executes them because they are not in a
function and then it executes that, this, that and that and then goes here.
So what will happen here is to dos.
This value will go as the value of the file path local variable.
This is an argument, but it's also a local variable in this function.
And the same goes for this.
So to dos at this point, it holds a list.
So to dos is actually a list.
So that list.
Object will go as the value of this to DOS underscore arg local variable.
So think of that list as a ball of tennis ball and you just throw it from one person to another.
So you throw it from one variable to another.
So at certain points one person has it, at another point, another person has it.
So that's the value of a ball.
And then the ball is used in this procedure, in this function.
And so the bowl then is written somewhere in.
The text file, so it's placed somewhere and then we see that seen here somewhere.
So if I run the script now, it should be working fine.
But I would like to also replace.
These lines as well.
So this is under edit.
This would also be right to do to do the text and to use.
So that goes there.
Same goes in here.
Right to do is to use the text to dose that variable so the user enters a number four to the item they
want to complete.
We read the to dos from.
The existing file using the get to this function.
So we grab that list in the to those variable we remove the to do from the list.
With pop.
So the list is now updated and then we send the list to the right to do this function.
And the function will get that list and it will write it in the to do the text file.
That's the idea.
So now the code is more organized.
We don't have repetitive codes.
If you if we want to change something.
Regarding the file reading process or the file writing process.
You just change that in here or there.
You don't have to change it everywhere in the code.
So let's try out the code now.
I'll add.
Clean the codes, perhaps show clean.
The code is added as the lost to the item, maybe complete.
Number two to the pizza was removed from the list show.
And that's the updated list.
And that's the complete code for today.
I would like to clarify the terminology of Bates beg for.
I close the video.
So this here, that and that are parameters are known as parameters.
So when you are writing them here in the function definition.
We tend to refer to them as parameters.
But then.
This.
Here is the argument value and the argument itself is this.
So if you mention the arguments in the function call, this is the argument and that is the argument
value and that is the parameter.
Now, this is optional.
You don't have to mention the argument name in here.
So this will work exactly the same if I run the code now, I can add.
By the painting and show, so by the painting is successfully added.
And so this is working just fine.
Now, which version should you use?
This or that?
Well, it depends.
So the purpose always is to have to make the code as clean as possible, as readable as possible.
So sometimes it might be useful to say here what this value is.
So that will make the code more readable.
As a programmer, you read the code you see over here.
This is a file path, so you understand immediately what kind of value this is.
But in certain cases like here, I don't think this is necessary because we know that by just looking
at this, we know that this is a file path.
We see the extension and this does look like a file name, like a file path.
So you don't have to mention that.
Same here.
If you wanted to mention the argument name, you'd say full faith is equal to that.
And here it would be to twos or is equal to that.
So file path is that parameter.
So the parameter name here argument.
So when we call the function, it is referred to as an argument, the argument and the argument value
and that's to this ARG which is mentioned in here.
And the value of that is the list.
Style wise, it is recommended not to have spaces around the assignment operator so this wouldn't be
recommended.
Therefore, just do without spaces.
It is recommended to have spaces around the assignment operator when you do normal variable declarations.
No matter if you are doing local variables like this one in here or global variables declarations.
So there are spaces white space around the assignment operator, but not here.
And in our case, I would prefer not to have the argument.
Names, but just have the values there.
I think this is clear enough and readable.
So thanks a lot for following and I'll talk to you later.