Hi, guys, how are you?
I'm all right, so let's get down to business and let's try to resolve the assignments of methods right
here.
OK, so once you open your by chance, as always, great.
And you file, you can call Python methods.
Practice.
Right, and then Mathis practice.
And let's try to see how can we resolve these two parts of the use of the assignments.
All right, so first of all, in part, you were asked to create a new method and call it sorting.
Right.
And the sorting variable, the sorting method should get arbitrary arguments.
So this is mentioned by these staff specially, and then we should put languages list because it's going
to receive programming languages.
All right.
And then inside the method, you first of all, let's go to the to this easy part.
All right.
So sorting should get three executions the first time.
It should be Python, then it should be JavaScript.
Then it should be C++.
I'm not sure this is was the order, I think that the C++ execution was the last one mentioned.
Oh, what's going on here?
Oh, I'm confused, I forgot quotation marks here, and that's it.
I'm not sure because I think that it should get the this execution should be the last one.
But the order is not meant matter really much.
All right.
And then we had Python and Java.
And we had something.
Fight on ops.
On.
Java.
And go, right.
OK, so we're good.
We have these three or three executions right here and now that's handle what will be the content of
this method.
So what you were asked to do in this in this method is basically to scan each item.
OK, so one item would be language in language like that and then print out whether it's Java or not.
OK, so if.
Language.
Equals equals Java.
Then Brent.
Um, language.
Like Jova.
Language.
Oh, shut up, language found, sorry, I was thinking about how to resolve it in a different way.
All right, this far we're good.
Let's try to run it.
OK, so you can see here that we have only two of these printouts of Java language found and accordingly,
right here we have these two which Java is mentioned in there by the first one, does not have Java
inside.
So up until this point, we're good.
We're OK.
And you also ask to do the following thing.
You're asked to scan once you get Java, you were asked to scan the Java variable and print the letters
of Java one about the other.
And we're going to do it right here.
You can see that like the cursor right now is blinking inside the method.
Correct.
Then afterwards I created a for loop.
OK, so we have a certain indention that I marked right here.
And this indention means that whatever comes here in the intention is inside the for loop, OK, because
the loop has less intention.
So now we're inside it if and this if is inside the for loop.
OK, and here we asked whether if language equals Java and inside the if we have more intention and
the print of Java language found this in here.
OK, but after we've printed out the Java language is found.
I'm not staying in this indention because this indention level is inside the F basically.
Yeah.
I need to stay here.
Yeah.
OK, so I'm just saying this indention right here because I want to stay inside the if because if I'm
inside the if it means that the currently Java variable is caught and this is what I'm looking for.
And right now I want to scan each of these letters right here and each and every one of them want to
print them.
So I'm going to do is the following.
We went over this in the previous in previous lectures, I think it was in variables, one of the first
lectures.
And in here, I want you just to write a for loop and mention here character in language like this.
All right.
So basically this will do is once you do print character.
OK, so now we have a for loop, which the whole one the whole unit is language is one word in our case
is Java.
And the one item inside the hole is a character.
It's going to break down the Java into one character each time.
So let's try to run it and see that we were OK.
Great.
All right.
So you could see Java language found.
Then we have Java printed one above the other as we were asked to do and just to be just using like
100 percent if this was an interview question.
If you haven't.
If I always mention the else as well.
And right here you can mentioned.
Like print, Jova was not found.
OK, so if we run it, we will see all states you can see here Gevalt found, Jonathan Geminid found
and only only one Java language found.
OK, so the Java was printed out.
So you can see right here.
All right.
So I think this concludes our assignment, our first assignment.
This will be printed each time.
We would not scan a the Java language, for example, Python, JavaScript or C++.
So you have JavaScript here, C++ here.
So sorry, Python here.
Yeah, JavaScript and then C++ or Python, JavaScript, C++ just going to match these values to the
outputs.
Then we're going to the next one and we having here by dawn.
OK, the next one in line is this one which is scanned and then we have Java OK, which is this output
right here.
So accordingly after Gervais's found we were printing the letters and then again we have Germinal found.
All right, which is despite unvaluable scan and then we have Java language found, which is this one
also printed out and the last one Javadoc found.
All right.
We can also mention here the name of the variable.
So it would be easier and we do not have to guess.
Right.
Like this.
Yeah, OK, so Python, Java, JavaScript, C++, then Python and all of these are not Java.
And basically you have your answer right here.
OK, let's just lose the empty lines.
That's it.
So what we see here is we have our method, which is this part right here.
It's like a bulk of code.
It's like a bag with goodies inside.
And separately, we have the execution level right here.
OK, so this is how it works.
You see here the method which is at the side and right here you can see the execution separately.
OK,
so this was part part A.
And I think we're ready to go to PABI now.
All right.
Oops.
And right here in Palm Beach, before we begin, I just don't want to have mixed outputs here, so I'm
just going to mark everything in power and use a control and backslash to comment it out.
So Pichon would ignore this code for now.
And let's start resolving Part B..
OK, so what do we have in Palm Beach?
We have in part B, a task which will be a tax calculation.
And first of all, we need to create for the first method, which is tax calculation, according to
the guidelines.
And it should be a gross salary.
And tax, OK?
In and inside of it, we should get net salary.
OK, we're going to calculate the net salary.
Yeah, and it should be gross salary and then reduce from meet
the gross salary.
You know what you can do.
It's like it's a metric.
OK, it's not a trick.
It's like a math calculation.
Indeed, in many ways I'm going to do the following thing, one which is like a hundred percent of the
salary.
If we leave it like that, like gross salary multiplied by one, we'll get 100 percent of the gross
salary.
But if we multiply it by one minus the tax, OK, so we will get a tax reduction in the net salary right
here.
OK, so we're getting one minus the tax and we're multiplying this value by our gross salary.
So our gross salary will be smaller.
It will be the net salary without the taxes.
OK, this far so good.
And then also please return the net salaries to just enter the keyword return and mention what do you
want to return.
I want to return the net salary.
OK, this far we're OK right from here.
Let's try to execute the first, the first one the like.
This is the first method.
We have two methods in this assignment, so let's try to execute this one and it's returning a value.
So I'm just going to mention it here.
Net salary and we're going to execute it three times.
So we need three separate value variables and then we have tax calculation and the first one gets five
thousand for the salary and zero point two for the tax.
Second one.
Let me just copy it to save some typing word.
Bill Gates once said that the best developers are the lazy ones because lazy developers don't waste
time on writing code again and again if you can find some shortcuts, so always do it.
It's not a negative thing.
The only effective.
All right.
So the second execution had 6000, the salary and Zurda 22.
And the last one was 10000 like this.
All right.
But right here, we have a small problem.
OK, so if you look at these three lines of execution, you can see the last line has like a gray background
here.
And once you hover above it, you can see Paramatta tax field because we missed something crucial.
All right.
We missed that.
You were asked to use a default value for the last one.
Let's have a look.
OK, so let me just find it
right here.
Notice that if no tax variable is fast into the method, it should use zero 22 by default.
All right.
So let me just get back to Vikram.
So we need to use some of default value.
We studied it in the previous lectures and just put equals here and put the default value like this.
So this will come in use only when we do not pass a variable into the method as it goes here in the
third execution.
So this would come into action and would be used.
All right.
So I think we're OK for this balustrade to run it and see that we're good.
OK, there is no errors.
I don't have any printouts.
So, you know, I can just print out here the net salary.
And plus, casting and net salary.
All right, just to see that everything's fine.
OK, so you can see reduction here from five thousand to four thousand.
From six to four forty eight hundred and from ten to seven thousand eight hundred.
So this far we're OK, but we have an additional assignment, additional method that needs to be created
and the method should be as follows.
OK, so the next method you're asked to create is salary limit testor, if I'm not mistaken.
Yeah.
Salary limit Testor.
Let's create it.
Like this, and it should get a net salary variable inside it.
By the way, notice that this variable received here does not have to be the same, which is passed
into the method.
OK, so right now I'm just going to do the following thing, salary limit Testor and put the net salary
one inside it.
OK, so you can see I offset inside net salary one, but it received net salary variable because you
don't have to match these names because this one's dynamic.
OK, inside the method and the first time and the first execution we put net salary, one bought in
the second time we put the necessary two, OK.
That's why this name is not connected to the name that is passed into the method is no connection between
them.
All right.
So just put a pass here because I see what when I don't put that you have a small red line under the
net salary under the end here.
OK, so for now, just going to put Bas here.
All right.
So I think we are prepared to put content inside this method right here and inside this method, you
were asked to check a simple thing if.
Net salary variable.
Is bigger or equal to five thousand eight hundred like this, and if it does, then print success.
Success.
The salary is.
And then just put casting and that Sellery variable and and just put a plus here.
Yep, like this, and if it's not, then we want us always to use the hours, which is the default exit
point and right here.
The salary.
He's under five thousand eight hundred years.
And podcasting.
And that salary variable.
OK, let's run it.
Oops, I clicked on the debug.
Yeah, OK, so the first execution with 5000 you can see like the net salary is 4000.
And the second method brings out the salary is under 5200.
It is four.
OK, so what happened here is we executed from top to bottom here.
We executed the first method.
We've said 5000 inside and to end up in here and we reduce the tax and we got the net salary.
Then we printed the net salary inside the first method right here, the net salary.
Then at the end, we have returned the value.
So the value value is returned to the execution level here.
OK, this thing returned us 4000 and it went straight up in net salary one.
This variable got four thousand.
Then we took this four thousand and we've set inserted it into this method, the salary salary limit
test and the variable went inside here and then it goes up in here inside the method.
OK, this thing gets four thousand and it gets to here.
Four thousand is smaller, is smaller than five thousand eight hundred.
So this case is false.
The statement is false.
So it goes straight to the house and inside the else we're printing the salary is under five thousand
eight hundred.
It is four thousand.
OK, same thing for the second thing is for the second run when we use the six thousand here and we
were reducing the tax and it gets four thousand eight hundred still under five thousand eight hundred.
But in the last one, once we reduce from ten thousand to taxes we get seven thousand eight hundred
and then once we put the seven thousand eight hundred inside here.
OK, success, this salary is seven thousand eight hundred.
So this pause right here is a true statement.
So this one is printed out.
OK, so it seems like there are two parts in method.
Those always two parts.
You have the part of the method declaration and method content.
OK, same goes here.
Declaration and content and the content.
You know, it's the content because you have indention here and right here we are executing the methods,
the not like not connected.
There are two parts here, the declaration and the execution.
OK, so the execution starts from here.
We execute the first method.
Then we get this variable, we put this variable inside here and the salary limit test gets the second
variable and then this thing is executed.
And then the second time all over again and all over again once more.
OK, I think we covered all method.
Stop these questions, surely going to be asked in interviews.
So it's really important to understand everything we did here.
You can also watch it maybe a second time if it's a bit hard for you.
And also you can just copy the file of the results, which is attached to this lecture and just play
with the variables and play with the methods and understand deeper what happened here if you had had
some trouble.
I think that all topics of methods, like most of them, were covered, covered here.
And we'll we are dominators in methods as well.
I'll see you in the next lecture where we start discussing object oriented programming.
Basically, we're going to use methods as building bricks or puzzle pieces.
Both methods for metaphors goes here.
I'm going to use them as puzzle pieces in object oriented programming, and we're going to use object
oriented approach by using methods in the correct way, in the structured way, same as professional
programming.
LS worldwide are using it and at the end we're really close to becoming a python ninja developer.
Thank you for this lecture and we'll see you in the next one.
Bye bye.