Hello to all of my students, and in this lecture, we will see the answers for if practice assignments.
So as soon as you open the project, the initial project just right, click on it, create a new file.
You can call it if statements.
Like if state governments practice as such.
And once you do also leave a comment.
So for the first assignment, right, you were asked to create a dictionary right here, create a dictionary.
Of employee's right of employees and just created employees equals curly brackets, and then we have
first one is Jack.
Jack is available for six working hours after him.
We have Russell.
Russell is a valuable thing, working hours, and last but not least, we have Karen, which is a valuable
for two hours.
All right.
So after we have this created, let's try to print it print of an employee's dictionary like that.
All right.
And right here, we have an extra ASCE like that, right?
And let's just do some casting to string.
Then we have employees enter the shrine to.
Right.
Click and run.
All right.
Great.
So our dictionary is ready.
Our basis for the next assignments is, OK, we printed it.
We have a successful print from here.
Let's go to the second assignment right here.
You were asked to find an employee.
Four, five to eight hours use, if so from here, let's just create an if statement and start going
cell by cell, meaning let's start going employee after employee.
So first one is we need to extract a value from the dictionary.
If you don't quite remember.
If you don't recall, you can just go back to the lecture where we discussed collections and inside
collections.
We have studied dictionaries.
You can see how to extract values from there.
Basically, it's done with with square brackets where you just mentioned, Jack, in our case like that.
And we want to find we want to find employees who can work between five to eight hours.
So we're going to do this by using the bigger equal sign like this.
And right here we can mention either or and.
All right, so which one is correct?
Obviously, it's the end because we want to find a value which is bigger than five and smaller or equal
to eight.
So we'll use the and logical operator and again, mentioned here, Jack.
Yeah, like that.
And with Jack, we're through not not really.
We have here also to make bigger equals to eight like this and now we're done with Jack.
All right, let's see here.
Great.
So we don't have any arrow here.
This just the one I wanted to check if we don't have an arrow, because you see right here, we have
like a small red dot indicates an arrow.
Just wanted to verify that the arrow, as we can see it right here, doesn't come from the statement.
So just out of the base here and I see the error is gone.
So this statement is correct.
So, again, we have extracted employee Jack, uh, its value, which is six.
And we asked whether six is bigger than five.
This statement is true.
And also and we want that the value would be smaller than eight.
All right.
So we have both values true here.
Right.
And all right.
So just just let me check.
Just print Zachs, for example.
Just verified.
Right.
Click on one.
Great.
So SSX is printed out.
Great.
So we made this condition successful because actually Jack is the one that fits this because Russell
isn't fitting this in count as well.
But we were asked in the Simon to check every cell so we can just handle with Jack and that's it to
complete the assignment.
We also have to use our IF and again, that's use here, Russell.
And also the same thing, bigger equals to five and the employee.
Russell.
Bigger equals the eight.
And right here, just print, Russell is the man.
For this job.
All right, so after this one, let's create additional alif for, uh, by the way, we forgot.
No, it's OK.
Let's forget a mention here, Karen, and also like this.
And then we're going to do bigger equals the five and employees again, Karen.
Smaller equals to eight.
Take Garen for this shift.
All right, and last but not least, we have the house here, which is the default exit point, right?
All right.
So we are done with this and we have a small error here.
We have a red red color under the here.
And that's because we didn't write anything under the first if they Jack for this one.
All right.
Let's try to run it.
See that we don't have any errors.
Right.
Click and run.
All right.
So thank Jack for this one, because once we go over all the employees, we can see that the value of
Jack is actually bigger than five and smaller or smaller than eight or equals to eight because we're
looking for someone to work five to eight hours and he fits it.
He's value six.
And all the other ones are failing to agree to stand for these requirements.
Right.
So they are failing to stand these requirements.
That's why Jack is selected for this shift.
So we're done for assignment number two.
Let's go straight to assignment number three.
And here we need to find someone to work the weekend, a valuable.
For two or four hours, so this is very crucial because here we have two or four hours.
So again, let's see and extract the values if employee Jack.
And double equals sign, right, because we want exact values of one, two or four.
And also here we want to use the logical operator or because the manager asks for not two to four hours,
it's not like it's not like this two to four hours, meaning we can use three hours.
Also know the manager asks for two or four hours.
This is why we use the logical operator or here.
All right.
And again, employee Jack.
And bring something, Jack is selected for the weekend shift.
We have small red arrow here because I didn't put this sign right.
And then we have if.
And we use the same thing for Russell as well.
Equals, equals.
By the way, here, for God to put equals equals four.
Yeah.
Like this now it's correct.
Rasoul equals to our employee Russell.
Equals equals four as well.
And here printing Russell fits.
For weekend shift and last, we have Karen here and we'll extract her name, her value.
Like this or equal equals equals do or employee Karen.
Equals equals four.
So we're done with Pathé off of the assignment, third assignment, we've we have completed the sub
assignment eight.
So this one, we're done with it right here.
We can also add just to complete completed totally.
Carrer will go work the weekend.
Right.
And at the end, as always, we use an else, which is the default exit point.
Yeah.
Brent.
The.
Alice.
Default exit point.
All right, and now we have some assignment B where the manager asked to see what the exact time that
Karen can work the weekend.
So we have to do some digging inside Karen's if statements, if statement, and we're going to use a
nested if for that one.
So, first of all, we're going to erase this code because we don't want to print anything.
And you know what?
Maybe you can do something like I upgraded that we haven't yet.
We can use we can run several lines here.
So let's bring first of all, let's bring Karen will work will go work that weekend.
And also under this print, we could mention if.
Employee.
Karen.
Equals equals to then Brent no, sorry, then we don't want to do anything.
This was the requirement, right?
So if the nestande if it's true, we don't want to do anything.
And that's why I'm going to insert a pass here.
This was the whole point of the assignments.
And also if Ayliffe employee employees, Karen.
Yep.
Equals equals four.
And also, we don't want to do anything right here, we just want to add a default exit point for that
nested if like this.
So right here, we're going to just add a nested.
Alice.
Brent, and the whole point of assignment three B is just to see that you don't have any arrows, all
right, because if you miss this house, for example.
You know, going to have any error, but I want you to do the whole point here was to use all the parts
that you need to use inside the if, use the F, use the alif, use the nested if you use the default
nested else and also use the parent else right here.
So we have all values right here.
Right here.
Let's try to print it right.
Click and run.
All right.
So first of all, as we already seen before, for the first assignment, Jack took the shift and for
the assignment number three and we have Karen will go work that weekend.
So this code works right here.
We already see that it works.
All right.
This ayliffe was executed before because Karen works for two hours.
We can see it here and the dictionary right here.
So now Karen was selected for the weekend shift because of this one.
And it's enough for only one requirement to be fulfilled because we have our logical operator over here.
So it's enough that this will be false.
We don't care.
But this one is true.
And also all of these are false.
So she was selected to be the one to work the weekend this this code ran.
And also we go inside the nested if right here.
All right.
And we don't want to print anything inside the working hours.
All right.
The boss wanted to know what is the exact time she can work in Karen.
Karen can work two hours.
So also the nested if this code was executed, just to check that the flow of code goes over here,
just want to do the the following thing, just print X, X, X and then run.
And as you can see, this code is executed while the other ELIF is not executed.
You can see if I put it here, the card will not go there and this would not be executed.
You can see the X now is not printed because it work.
It goes through here.
All right.
So and this assignment, the code flow goes from here is false.
This one is false.
This one is true right here.
This is true.
So it goes inside.
It goes through here.
And then we handle the nested if which is all of this part.
So we go from here from top and then it goes straight to the pass right here.
All right.
This thing is not executed at all.
That's that's about it.
All right.
So I think that we have covered all the parts of if statements, all the information that we have learned
in the theory lectures we have covered in these assignments.
I really hope that if you have some trouble, this lecture helped you to see some things more clearly,
because I think here all the small features that f f statements has and how to use nested if inside
the code using a dictionary.
Also, I think this makes you dominators in the if statements part.
And right now we're going to go straight ahead to the next lecture where we start talking about loops.
And also in the loops, we're going to discuss how to use a loop using dictionaries and using and how
to use collections.
In general, we're going to apply collections along with for for loops.
And that's about it.
All right.
Thank you, guys, and see you in the next lecture.