Loading...
Hello, I'm Mrs. Holbrook, and welcome to computing.
I'm so pleased you've decided to join me for this lesson.
We are going to be using selection in Scratch to make a chat bot respond more appropriately to the user's input.
Are you ready to make a start? Welcome to today's lesson from the unit, "Fundamental Programming Constructs in a Block-Based Language." This lesson is called "Selection." And by the end of today's lesson, you'll be able to use selection to provide more than one path through a programme.
You'll need to have access to Scratch for this lesson, and it would be useful if you had your worksheet ready.
We will be exploring these key words during today's lesson.
Expression.
Expression, a combination of logical and comparison operators that result to True or False.
Selection.
Selection, used when there is more than one possible path for a programme to follow.
If statement.
If statement, used to carry out selection in a programme.
If block.
If block, used to carry out selection in Scratch.
There are two main parts for today's lesson.
First, you'll recognise outcomes of conditions are True or False.
Then you'll move on to modify a programme to include selection.
Let's start with recognised outcomes of conditions are True or False.
Is this statement True or False? The colour of this card is red.
That's right, it's True.
The card is red.
Is this statement True or False? The suit of this card is diamonds.
That's right, it's False.
The suit of the card is hearts.
Is this statement True or False? The colour of this card is red.
That's right, it's False.
This card is black.
Is this statement True or False? The suit of this card is spades.
That's right, it's True.
You evaluated the expression for the cards to either True or False based on the condition.
Andeep says, "In programming, a selection statement allows a computer to evaluate an expression to True or False and then perform an action depending on the outcome." Let's see some examples in some code blocks.
Here I've got a Scratch block that starts with the when green flag clicked event.
It's then got an if else selection.
And inside that if, I've got a condition which says item equal to vegetable.
If that condition is True, it's going to remove the item.
If it's False for the else, it's going to keep the item.
What items do you think will be removed when this code block is run? Pause the video and have a think.
That's right, the broccoli and the aubergine have been removed because they're vegetables.
The cherries, the apple, and the banana are all fruits so they've been kept.
Let's see another example.
This time the condition inside my if statement has changed to item equal to red.
Which items do you think will be removed this time? Pause the video if you need to have a think.
That's right.
The cherries and the apple have been removed because they were both red.
Only the banana is left.
Let's check your understanding.
How many items would be left after this condition? Is it? A, 2.
B, 5.
Or C, 3.
Pause the video whilst you have a think.
Did you put 3? Well done.
Any item that was red was removed, so we're only left with three items. In Scratch, the operator blocks can be used to create expressions: the less than block, the greater than block, and the equal to block.
Let's check your understanding.
Which operator block checks if the variable score is less than 10? Pause the video here whilst you have a think.
Did you select A? Well done.
A is the operator block that would be used to check if the variable score is less than 10.
Okay, you're doing fantastic so far, but we're going to move on to our first task for today's lesson.
Look at the Scratch code block.
Complete the table by ticking whether the outcome of the expression is True or False for each value held in the variable weather.
Pause your video here whilst you complete the task on your worksheet.
For part two of task A, you need to match the operator to the description.
Draw a line between the operator and the correct description.
Pause the video whilst you complete the task.
For part three of task A, you've been asked what happens if the user answers "no" when they are asked if they are ok in this programme.
Look carefully at the code block and write down what you think will happen.
Pause the video whilst you complete the task.
How did you get on? For part one, you were asked to look at the Scratch code block, and then complete the table by ticking whether the outcome of the expression is True or False for each value held in the variable weather.
So, in our first row on the table, we have that the value held by weather is warm.
That condition would be True because the condition is checking with weather is equal to warm.
The next row, the value held by weather is cold so that expression would return as False because weather is not equal to warm.
For the second part of task A, you were asked to match the operator to the description.
Temperature is 16 is the top operator.
The next one down is temperature is less than 16.
And then the last one is temperature is greater than 16.
Check your answers match those on the screen.
For part three, you were asked what would happen if the user answers "no" when they are asked if they're ok in this programme.
Here is a sample answer.
The programme will not display anything as the condition will not return True.
In order for the programme to say "Good, glad to hear it!" then the user must have responded "yes." We're now moving on to the second part of today's lesson, and we are going to modify a programme to include selection.
Selection is used when there is more than one possible path for a programme to follow.
And if statement in Scratch is represented by the if block and is used to carry out selection.
You'll notice here the if block has got an empty space where we can place in our operators that we've just seen in the first part of today's lesson.
The if block allows you to check an expression and perform an operation if it evaluates to true.
If the expression evaluates to false, then the operation will not be carried out.
An if block with an else allows us to perform a different operation if the expression evaluates to False.
Okay, you're doing a great job so far, but let's do a quick check.
Which block lets your programme perform a different action if the expression returns False? Is it? A, if.
B, if else.
Or C, forever.
Pause the video whilst you have a think.
Did you put B? Well done.
An if else will allow your programme to perform a different action.
if the expression returns False.
In our fruit and vegetable programme, the if statement is used to check if the item is a vegetable.
If this is True, then the item is removed.
If it is False, then the item is kept.
So Sophia correctly is saying, "This means only fruits are selected in this programme." Okay, let's check your understanding what is the difference between programme A and programme B? Pause the video here whilst you have a think.
Did you have time to see the difference between the code? Here's a sample answer.
Programme B has an else statement, which means if the first condition returns false, it'll perform a different operation rather than just moving on.
In this case, it displays "Put your coat on" if the first condition is not met.
Okay, we now moving on to the second task of today's lesson.
You're doing a great job so far, so well done.
For part one of this task, we're going to use Big Ed, our friendly chat bot.
Open the Scratch programme, oak.
link/big-ed-feeling.
Before you run the programme, look carefully at the code and make a prediction about what you think will happen when the green flag is clicked.
Pause the video here whilst you open the programme and have a look at the code.
For part two, you can now run the programme.
Were your predictions correct? Pause the video whilst you run the programme and compare your predictions to how the programme runs.
For part three, you need to amend the how_are_you subroutine so that if the user says "no" to the question "Are you OK?" then it responds with the following, "Oh no, hope you feel better soon." Pause the video here whilst you complete the activity.
Okay, for part four, you're going to open another Scratch programme.
This time you need to open the file oak.
link/big-ed-quiz.
This programme includes all the code you need to get Big Ed to ask a quiz question.
Place the code blocks in the correct order to make the programme work correctly.
Pause the video whilst you complete the activity.
Okay, for the final part of this task, part five, you can extend the programme to include more quiz questions.
Quick hint, you're going to need a new routine for each question.
Pause the video whilst you have a go at the activity.
How did you get on with your code? Well done.
You've done a great job so far.
So for part one, you were asked to make a prediction about what would happen when the green flag was clicked.
Here's a sample answer.
"I predict that the programme will start with Big Ed saying 'Hello' and what his name is.
The programme will then ask three questions: 'What's your name?', 'Are you OK?', and 'Is it your birthday today as well?' Big Ed will then give a suitable response depending on what the user inputs." For part three, you were asked to amend the how_are_you subroutine so that if the user says "no" to the question, "Are you OK?" then it responds with, "Oh no, hope you feel better soon." You can see here the completed code block for the solution.
So we've put in an if else, so if they say "Yes," the programme is going to say, "Good, glad to hear it." But if that condition returns False and they say "no," then it will say, "Oh no, hope you feel better soon." If you need to amend your code, you can always pause the video here and make any corrections.
For part four, you were asked to open the new Scratch programme big-ed-quiz.
You were then asked to place the code blocks into the correct order to make Big Ed ask a quiz question.
Here is the solution with the code blocks.
We've got a subroutine for question one, which starts with asking, "What is the capital city of Spain?" We then set the variable capital_of_spain to answer.
Remember, answer is a default variable that stores the user's input in Scratch.
We then have an if else block with the condition capital_of_spain equal to Madrid.
If that condition is True, then the programme says that is correct and we're changing the score variable by 1.
If that condition returns false, then we are saying incorrect.
Remember, you can pause the video here and make any corrections to your code.
Okay, we've come to the end of today's lesson, and you have done a fantastic job building selection into programmes in Scratch.
Let's summarise what we have learned today.
An expression can evaluate to True or False based on a condition.
Selection is used when there is more than one path for a programme to follow.
If statements are used to carry out selection in a programme.
The if else block allows for a different operation if the condition of the if statement returns False.
Great work, and I hope to see you again soon.
Bye.