Lesson video

In progress...

Loading...

Hello, my name is Mrs. Holborow, and welcome to Computing.

I'm so pleased that you've decided to join me for this lesson.

We are going to use comparison and logic operators in Scratch to make a quiz.

Are you ready to make a start? Welcome to today's lesson from the unit using fundamental programming constructs in a block-based language.

This lesson is called operators.

And by the end of today's lesson, you'll be able to create complex conditions using comparison and logic operators.

You'll need to have access to Scratch for this lesson and it would be useful if you have your worksheet ready.

We will be using these keywords during today's lesson.

Comparison operator, comparison operator, an operator that is used to compare one value to another.

Condition, condition, used to control the path a program follows.

Logic operator, logic operator, an operator used in a logical expression, for example, and, or, and not.

There are two parts to today's lesson.

You'll start by creating conditions using comparison operators.

Then you'll move on to creating conditions using logic operators.

Let's make a start with the first part of today's lesson by creating conditions using comparison operators.

This program uses a comparison operator.

Can you see where it is? That's right.

This condition compares the value of health to yes and then checks to see if they match.

If they do, it'll say good, glad to hear it.

If they don't, it will say, oh, no, hope you feel better soon.

Comparison operators compare the values of expressions.

This first one, score equals 10, uses the equals comparison operator to check if the score is equal to 10.

The next one, score less than 10 uses the less than comparison operator to check that the score is less than 10.

And the final one uses the more than or greater than comparison operator to check if the score is more than 10.

Time for a check, fill in the blank to correctly complete the sentence.

Compare the values of expressions.

Pause the video here whilst you have a think.

That's right.

Well done.

Comparison operators compare the values of expressions.

Is this statement true or false? The card's value is equal to five.

That's right, it's true.

The card is the five of hearts so it is equal to five.

Is this statement true or false? The card's value is equal to five.

That's right, it's false.

This is the 10 of spades, so it's not equal to five.

Is this statement true or false? The card's value is less than five.

That's right, it's false.

The card's value is 10, so that's greater than five.

Is this statement true or false? The card's value is more than three.

That's right, it's true.

The card's value is five, and that's more than three.

Okay, it's time for your first activity of today's lesson.

Imagine that you run this program three times.

What will the program say if the year group variable is set to the following values each time? So A, set year group to four, B, set year group to six, and C, set year group to eight.

Pause the video here whilst you have a think and complete the activity.

How did you get on? Hopefully, you have these as your answers.

For A, set year group to four, the program would output primary school quiz.

For B, set year group to six, the program would output primary school quiz.

And for C, set year group to eight, the program would output secondary school quiz.

Okay, for the second part of task A, you need to open the program oak.

link/school-quiz.

You then need to complete the condition by adding a comparison operator to the question one subroutine.

The program should say correct if the answer to question one is four, the code block has been started for you, but you'll notice that there is a missing part where you need to add the comparison operator.

Pause the video here whilst you complete the activity.

How did you get on? You're doing a fantastic job.

Well done.

So in that missing part, in the if statement, you should have used a comparison operator with an equals.

You then needed to have the question one variable block and then in the answer bit, you needed to have four.

'Cause the correct answer for question one is four.

If you haven't got that quite right, don't worry, you can always pause the video here and correct your code.

Okay, we're now moving on to the second part of today's lesson where we're going to create conditions using logic operators.

Logical operators are used in logical expressions.

There are three main logical operators, and, or, and not.

And is true when both values are true.

Or is true when one or both values are true.

And not is true when the value is false, not true.

It's basically reversed.

Time to check your understanding.

Match the logical operator to the correct description.

Pause the video here whilst you complete the activity.

How did you get on? Let's go through the answers.

The and should be matched to true when both values are true.

The or is true when either or both values are true.

And the not is true when the value is false.

Well done.

Okay, back to our cards.

Is this statement true or false? The card's value is equal to 10 and the suit is equal to spades.

That's right, it's true.

The value of the card is 10, and the suit is spades.

Both conditions are true.

Is this statement true or false? The card's value is equal to five and the suit is equal to spades.

That's right.

This one's false.

The card's value is equal to five, but the suit is equal to hearts, not spades.

So both conditions are not true.

Is this statement true or false? The card's value is equal to five or the suit is equal to spades.

That's right.

This is true because we've got an or only one of our conditions has to be true.

So the value of the card is five.

So that condition is true.

So the statement is true.

Is this statement true or false? The card's color is not red.

That's right, it's false 'Cause the card is red.

In Scratch, the logic operator blocks can be used to construct logical expressions.

They can also be combined with comparison operators.

So you can see here we've got suit is equal to spades or suit is equal to clubs.

What are each of these conditions checking? The top one is checking that the number is greater than 30 and the country is equal to Spain.

Both must be true.

The bottom one is checking that the number is greater than 30 or the country is equal to Spain.

Either or both must be true.

Time to check your understanding.

In Scratch, which logical operator would you use to check if two values are both true? Pause your video whilst you have a think.

That's right, it's C, the and logic operator.

Okay, it's time for your final activity of today's lesson.

Open the Scratch file oak.

link/school-quiz.

This is the same one that you used for Task A.

Complete the Subroutine for question two, which asks the user which river Paris stands on.

For Part A, the program should say correct if the user gets the answer correct.

For part B, the program should say wrong if the user gets the answer wrong.

And there's a hint for you, the correct answer is Seine.

Pause your video here whilst you complete your activity.

How did you get on with your code? You're doing a great job.

Well done.

So here's a sample answer.

We've got the subroutine for question two.

It starts by asking, Paris stands on which river? It then sets a variable q2 to the answer that the user is going to input.

It then has an if-else block.

Inside the if-else block, we have a condition that says is question two equal to Seine? If it is, then we're going to say correct.

If it's not, and the condition is not met, then we're going to say wrong.

Remember, if you've got a bit stuck on this and you need some help, you can always pause the video here and correct your code.

Okay, you're now gonna complete the subroutine for question three, which asks the user to name a country that borders France.

Pick one of the following, Germany, Spain, Russia, or England.

The program should say correct if the user gets the answer correct and the program should say wrong if the user gets the answer wrong.

Now, this one has two possible correct answers.

So to get correct, the user needs to enter either Germany or Spain.

Pause your video here whilst you complete the activity.

How did you get on? You're doing a great job.

Here's a sample answer for part three.

We've got a subroutine for question three, which starts by asking the question, name a country that borders France.

Pick one of the following, Germany, Spain, Russia or England.

It then sets the q3 variable to answer.

We then have our if-else statement with our condition.

This time though, because there were two possible answers, we've used a logic operator.

So we've got if q3 is equal to Germany or q3 is equal to Spain, then say correct.

If that condition is not met, then it's going to say wrong.

Remember, you can pause your video and correct your code if you need to.

You're now gonna build the final question for your quiz, question four.

But unlike the previous questions, this questions has two parts.

So for part A, you need to first ask the question, what do the U and S stand for in USA for five seconds? You're then going to break it down into two parts.

Ask, what does the U stand for in USA? Then ask, what does the S stand for in USA? Store the user's answer for each question in a variable called q4-1 and q4-2.

So you're going to need two variables.

And then create a condition that will check that the user has got both parts of the question correct.

If they have, display correct, if not, display wrong.

So the user must get both parts of this question right for the program to output correct.

Pause your video here whilst you have a go at the activity.

Great work.

Let's go through a sample answer for part four.

So we've got our question four subroutine, and we start by saying the question, what do the U and S stand for in the USA? We then break that down into the two parts and we ask, what does the U stand for in USA and we store that value in a variable called q4-1.

We then ask what does the S stand for in USA and we store that value in a variable called q4-2.

We then have our if-else statement.

Inside that if statement, we have a condition using the and logic operator.

So we've got q4-1 equal to United and q4-2 hyphen two equal to States.

If both of those return true, then it's going to say correct.

If just one of those conditions is not true or if both of those conditions are not true, then it's going to say wrong.

Remember, if you've got a bit stuck, you can always pause the video here and correct your code.

Okay, one final part if you've got a bit of extra time today.

Extend the quiz game by adding a score variable to add one to the score each time the user gets a question correct.

Pause your video here whilst you have a go at the activity.

How did you get on? Did you manage to create the score variable? Let's have a look at a sample answer.

So on the left-hand side, we've got the main code block, which is controlled by the when green flag clicked event.

Underneath that when green flag clicked, we're setting score to zero.

This is setting the score variable to zero at the start so that every time the user restarts the quiz, their score is set back to zero.

Now, each time the user gets an answer correct, we need to add one to their score.

So here I've taken the example of the q4 subroutine, but, hopefully, you've done this in all of the questions.

So you can see underneath the if statement, so if they get the answer correct, we're changing score by one.

So this updates the score variable by one when the user gets the answer correct.

You've done a fantastic job today, so well done.

Let's summarize what we have learned.

Comparison operators can be used to compare values in a condition.

Logic operators, and, or, and not, can be used to build more complex conditions.

Well done for all your hard work today and I hope to see you again soon.

Bye.