How do all of the ninjas that are following these lectures after covering the previous lecture where
we went over the segments, now it's time to show the answers for the assignments, which, as I said,
are a bit challenging.
And as you might experience, as they have a combination of a lot of topic, lots of topics mixed together.
All right.
So as soon as you open the project, as always, create a new file, you can call it for loops practice.
All right, and also here for Loop.
Practice and before beginning and just going to copy here all of the rules that we had.
All right.
Like this.
All right.
And as you can see here, it's all marked in green.
It's the same as doing like this.
All right.
So this code will be ignored.
And the reason it's in green, because I put these three quotation marks at the beginning and at the
end and everything that I write in between is a comment.
All right.
So these are the demands of the assignment and this is the list that we need to address to.
And I'm just going to copy it as the beginning, because it's the same list.
No thinking is applied here.
So create a list of businesses.
All right, so right here we have the list of businesses that we need to apply the rules about and let's
begin.
All right.
So first of all, let us create a loop and the loop will be full loop and we shall have an in part in
businesses business.
We need to put business.
And as you can see, we have an error here because we need to pull something off the floor and I'll
call it single income like this.
All right.
So we have the whole list right here.
And we have the single income, which is one sale out of these these guys right here and inside the
follow.
We're going to do the following thing.
We're going to, first of all, break down all of these four sections right here because we want to
have some statements which will limit the taxes according to these incomes.
Right.
This is the only way to do it.
So let's begin with the first one.
If single income is between is bigger or equals one, because we don't want to take taxes from someone
who doesn't make any profit.
And and we use and because we have these two limits, so we want something to be bigger than one and
smaller than two thousand is the way to do.
All right.
Single income like this, smaller equals than two thousand.
All right.
Because if we put some, for example, or here, so we're going to get under here under the if only
values that are one or two thousand and we don't want it.
We want to get everything which is between one and two thousand and not to get one or two thousand.
Right.
And now the thing that we want to do is take a single income and take five percent out of it.
Right.
So how do we do it?
How do we take five percent, which is doing the following thing?
All right.
We're doing the following thing.
We're taking we're multiplying it by zero dot zero five.
This is five percent.
All right.
So and how how do I go to this conclusion even without knowing any mathematics if we do this thing?
All right.
So if we do this thing, we multiply as any number multiplied by one, we will get a hundred percent.
Or in other words, we're going to get this value again.
Right, because we got the 100 percent.
But in this case, we want to get only five percent out of the whole value.
So to get five percent, we need to multiplied by zero zero five.
OK, so once we multiply like this, we want to put this value inside something.
Right?
So let's create an additional variable which which we can call it tax.
Right.
Like this.
And this is what we're going to do.
We're going to take the value, for example, one thousand five hundred multiplied by zero zero five.
And this will be the tax that we got from it.
OK, so we're going to do the same thing for the second element as well.
If a single income is bigger or equals to 2001, because here we go up until 2000 and we don't want
to put 2000 here as well, because then there is the same number here and here and it's collides.
It's not good for us because the same number can go higher and higher as well.
And it's not good for us.
So we will start off 2001.
All right.
And single income up until how much do we have here?
5000 like this.
All right.
And again, we just copy this thing and just change the the number of the tax percentage at the end.
And what you want to put here is 10 percent of 10 percent is not one.
All right.
Afterwards, if single income bigger equals to five thousand and one and single income is smaller equals
to fifteen thousand, I'm just applying like what I found here in this section.
I'm just applying to you, applying the same thing here.
And here as well, it's the same rule.
OK, you see, I'm not just I'm not like investing any thinking after I figured out what to do here.
I'm just copying the same thing, just changing the numbers here, here and here.
OK, changing the limit.
All right.
Which the limit is this this thing right here and changing the taxes.
The part right here.
OK, this the only thing I'm doing.
All right.
So now we have five, a 500000.
And for that we have we need to copy this thing again and copy it basically here.
And for this thing, we need to take 15 percent.
All right.
And the last condition that we have is right here above 15000 will pay 17 percent for gross income.
So everything which is not this thing, because here we covered all the numbers.
We covered all the numbers from one to.
Five fifteen hundred fifty fifteen, fifteen thousand, sorry, so we covered here fifteen thousand,
OK, and now we're going to say else, which is everything which is bigger than fifteen thousand will
be here and we're going to take taxes, which is 17 percent.
And just going to copy this again and put it here and change it to 17 percent like this.
OK, and we're done with a part of taking taxes.
All right.
And now I'm just going to use backslash backwards backspace, OK?
Because I don't want to write code inside the house anymore.
And I want to put it outside of the if else.
OK, so where the cursor is blinking right now, it's outside this if else.
OK, this is outside that if else.
OK, all right.
Just remove redundant spaces, OK.
And right here I would like to do the following thing.
I'm going to create a new variable net income.
Yeah.
And I'm going to do a single income.
Minus tax.
OK, so what I did here is take the single income, which is this number right here, for example,
OK, and I'm going to remove the taxes, OK?
So, for example, the result of here is going to be five percent, OK, this the tax number is five
percent out of this number.
OK, so let's say, for example, that for the first number, five percent is like 15.
Just guessing know without calculation, just guessing 15.
OK, for example.
So if it's 15, I'm going to take the single income, which is the whole income right here, and I'm
going to reduce the tax.
OK, so I'm doing one thousand five hundred minus 15 and this will give us that net income.
OK.
Net income with this net income, what are we going to do is obviously is this section right here,
OK, because we need to calculate the net income right here and reduce two percent out of it to find
out what is the health care.
All right.
What is the health care amount that we need to pay?
All right.
So we're going to do the following thing now.
We're going to calculate the calculate the income.
After health care.
Reduction, because this is what we were asked to do in the fifth section right here, just want to
print it, just get the net income after reducing the two percent here and just print it.
All right.
Just print it.
So this would be the net income.
All right.
Multiplied.
By two percent.
Yeah, and right, like the the health care reduction is two percent, two percent.
Correct.
So instead of doing reducing two percent and then then taking the net income and deducting this number,
this number out of the net income, which is going to do the following thing.
OK, zero dark.
Ninety eight.
OK, so we're taking the whole net income and we're multiplying it by 98 percent.
And this would be the 98 percent that we have after reducing the health care right here.
OK, so this results right here will take the net income and reduce two percent out of it because we're
multiplying it by 98 percent.
Is taking the net income multiplying it by 98 percent?
This will give us the the income after reducing the health care.
OK, it's a bit mathematical here, but this is the whole point, right?
Like combining several topics all together.
Correct.
OK, we're good this far.
Let's print it.
OK, print printing income after health care reduction.
Guaranteeing income after health care reduction.
All right, so we're done with this part and now we're going to head off to the last part, OK, am
right here.
Calculate the total tax you got from the give in to businesses in the list, excluding health care.
So we're just ignoring this pass right here, ignoring it, completely ignoring it completely, because
for us, this thing doesn't doesn't come into calculation once we are talking about reduction of taxes.
So we're going to do the following thing.
Right.
Total taxes.
Is.
Total taxes.
Lost X.
OK.
So you see here.
Total taxes can be you see that what I'm doing.
You just need to learn from this practice as well.
You see, I have here a brownish background like patroness, trying to tell me there is something wrong.
It's not an error because it's not red, but something is a bit wrong.
All right.
So hovering over it, I can see name total taxes can be undefined, meaning that there can be a case
where total taxes will have no value at all.
OK, so he wants me to define it to something.
Doesn't matter what does something.
So I'm just going to define it here outside of the loop.
Total taxes, but zero here or even the keyword, none like this.
And just to define it to something so he won't shout at me here and it's none.
OK, so let's see what I did here.
OK, well, let's see what I did here.
What actually did here is the following thing.
Let's say we're going for the first run.
We're taking this value and we're starting to run over the loop here.
OK, so we have one thousand five hundred going from the top.
And are we going inside this IEF?
Are we.
Yes.
Yes, we are.
Why?
Because it's one thousand five hundred.
It comes inside this limits right here, correct?
Yeah.
OK, now what happens?
We're taking the single income, which is the one thousand five hundred, multiplying it by five percent.
OK, this will give us the tax that we get from that 100 percent.
OK, this is the one hundred percent.
One thousand five hundred is the whole number, the one hundred percent.
We want to know how much is five percent out of this whole number.
And this is the tax.
So we got the text of the first number going downwards with the code, are we doing something in this?
If no, because we already got into the first if something, he'll also know something inside the house.
Also, nothing happens here.
OK, we now completed the if al spot.
Now we're coming to this pass right here.
Right.
So here we have the following thing.
OK, here we're taking the tax that we have, OK, the tax from here, this value that I'm marked right
here, taking the tax and we're taking the single income, OK, which is this one, one thousand five
hundred.
And we're reducing from the single income.
The Texas.
OK, this will give us the net income, this is the net money that we're going to have in our hands
after we're reducing the taxes.
OK, after we completed this thing, now we want to know right here, as we already discussed, all
businesses will pay additional two percent full health care from the net income.
OK, just print it.
So we're having here getting the net income that we have, net income and we want to know how much money
do we have in our hands after using these two percent?
OK, so in total, we have 19, eight percent of our salary.
So just take the net income and multiply by 98 percent.
OK, so this is the money that we have after paying for health care.
Then we're going to the seventh section right here, six section, sorry, while excluding health care.
So this part for us, it does not exist anymore at all because now we're in the sixth section and it
says here, exclude health care.
So we ignore this part completely.
We don't care about it.
Here we did some calculation.
We created a new variable income after a health care reduction.
But this net income stays the same.
OK, stays the same.
And actually, we don't care about it at all.
OK, because now we're going to deal with the taxes.
This part right here talks about the taxes.
We don't care about net income, not that income.
We don't care about it.
Now we're talking the taxes, the tax already collected here and it's safe for us in waiting for us.
Nothing happened with this tax value.
It stays the same as we started going from top to bottom.
So we have already a number here of tax, OK?
And in this part right here where we want to know what is the total tax you got from the given 10 businesses.
So this loop here is going to go once, twice, three times, four times and so on until we complete
the whole list right here.
Correct.
The whole list right here.
It's going to go around at around 10 times, right?
One, two, three, four, five, six, seven, eight, nine, 10 times.
Going to go again and again and again.
And we need to somehow collect in each cycle the taxes that we got.
OK, so what I'm doing right now in this section right here, I'm just creating a new variable, which
equals to nothing, OK?
It equals nothing at the beginning.
What's going the first time?
It equals to nothing.
And I'm saying the following thing.
Take nothing and the first time and add that tax number.
OK, we got the tax number from here at the first time and just take nothing, plus the tax that we
got from the first cycle, OK, and put it inside here inside the total, for example, to make it easier
for us to understand, let's say that we got in Texas here we got the number one.
OK, just for the example, just for the theoretical example, let's say we have the number one here.
OK, so there is nothing plus one.
And all of this part, all of this part goes into here.
So once getting to this goal, once getting to this goal right here.
Right.
We're having one here, OK, then we're finished now and this part right here, the first loop cycle
finished and here we have one starting again with the second cycle, taking this number, going through
all of this loop right here, going inside this part, inside this IV here.
By the by the way, it's not if it's elif of course this also elif.
Yeah.
Because if we have more than one, if we use out if elif and at the end we use else in the second part
we're starting from the top and we're seeing here the number two thousand five hundred forty two.
It doesn't fit here because it's bigger than two thousand and the number of feeds over here.
Again we take the taxes OK and going downwards and coming to this line again.
OK, you remember what number we have here.
We have here one.
Right.
And then we calculate this thing again.
So here in total taxes, we have one from the previous cycle and then we adding it to the taxes that
we got from the second cycle, from this number, OK, from this number we got here in the second cycle,
inside this part, inside this ELIF and we got a tax number from here.
So we taking that one number, number one that we got from the first cycle and adding it to tax variable.
Tax variable is the taxes that we have taken from this variable right here.
Correct.
So then in the second cycle, what we did here, we took the taxes from the first cycle and added it
to the number from taxes from the second cycle.
And all of this got into total taxes.
And then in the third cycle, we have Texas from cycle number one and number two, and they're added
to Texas from cycle number three and so on and so on.
So what eventually happens here that in Texas we have eventually at the end, once we finish this thing
as well, we have our total taxes summed up again and again and again until we have all the taxes collected
over here.
All right.
So now once we have it, let's go to the end of the to the most left part here, because we want to
be outside of the loop now, OK, outside of the for loop.
And as long as we have indention like this, we're inside the loop.
Once we do backspace, we're outside of loop.
And now I just want to print print the sum of print, total of taxes, OK, loss casting total of taxes.
OK, that seems correct.
Let's run it and see what happens.
And we have an error.
OK, so we have unsupported operator type plus non type and float in line number 46 and we're seeing
here that we have some kind of error.
Correct, because we're trying some type error.
Unsupported operand.
So we have some kind of error, we have types for the plus because we cannot add a non type and float.
So I think the arrow is right here because we cannot add none to a number, so let's just zero here.
Let's run it again.
All right, all right, so I think we're good now.
OK, so right here you can see the printing income after health care reduction.
And let's just check ourselves.
So we're seeing here, by the way, let's do an additional thing we're seeing here, the printout of
income after health care reduction.
Correct.
But I want to do an additional thing.
I want to print the print print of the tax variable.
Yeah, I just want to print it as well.
All right.
And after these two printed, let's just do print and do have some spaces, so be more ordered for us
like this.
All right, so let's go to the top.
OK, so from the first one from this guy right here, one thousand five hundred, we took seventy five
dollars tax, OK?
And then we have Brint income after health care reduction.
It's one thousand three hundred ninety six.
OK, so basically this is the tax that we took, OK, and this is the present income after health care
reduction.
All right.
So let's just verify using a calculator and let's calculate if it's correct.
OK, so we have 1500.
OK, and first of all, we're reducing five percent, five percent taxes, so let's multiplied by zero
zero five.
So 75 is the same as we have here in the tax printout.
And once we reduce the taxes, we have the net income income, which is one thousand five hundred minus
75.
This is our net income.
OK.
And from this summary right here, the net income, we're going to check out how much is 98 percent
of it.
OK, so this is one thousand three hundred ninety six point five, which is the exactly the number that
we have print income after health care reduction.
So our calculation is correct in the printout.
And OK, so we see here the printout all along the way.
And you can see here we have a float number with lots of number after a decimal.
And who doesn't?
We don't care about it.
Like usually people don't use these numbers after a decimal point.
We learn in the next videos how we can limit this to two numbers or three numbers doesn't matter.
But for now, the correlation is good.
And once taking all of these numbers of taxes altogether, we have fewer taxes.
Print of total taxes, three thousand six hundred and seventy point forty five.
This is the summary of all of these taxes right here.
OK, so this is the code for all of these requirements right here.
It's a bit challenging.
All right, because you have lots of math here and percentage if you need some strengthening in percentage,
go to Google and just learn quickly in 10 or 15 minutes how to use the percentage.
It's not very difficult because if, for example, you want to know how much is five percent out of
a number, you just multiplied by zero zero five.
OK, if you want to know how much is 10 percent.
So it's zero that one 15 percent, zero dollars 15.
It's math.
It's not programming.
It's just simple math.
OK, so, OK, this is a resolution for the practice part for for loops.
I think that this sums up the four loops completely.
And I think that now we are masters in full loops.
If statements, variables, lists, lots of topics, I think we're done with about 70 percent of the
pie out of the python course and and we're done with for loops in the next next videos.
We're going to cover other loops as well, which are pretty much similar to follow.
So if you understand for loops, the next videos will be pretty much easier for you.
Just have some different characteristics with other with other loops.
But it's pretty similar, pretty similar techniques for all four loops.
Just the basic thing we're going around and around again and again in the loops.
This is their purpose and I think we're done with this lecture.
OK, great job, everyone.
I will see you in the next video and bye bye.