Loading...
Hello, my name is Ms. Powell and welcome to Computing.
I'm so pleased that you decided to join me here today.
In today's lesson, we're going to be learning how to use conditions to make a quiz.
Let's get started.
Welcome today's lesson from the unit: Using selection and programming to develop a quiz.
This lesson is called Using Conditions to Build Quiz Questions.
By the end of today's lesson, you'll be able to explain how selection directs the flow of a programme.
We'll be using these keywords throughout today's lesson.
Let's take a look at them.
The first word is selection.
Selection: This is a part of a programme where if a condition is met and a set of commands is wrong.
The next word is condition.
Condition: This is a statement that can be either true or false.
And the last word is outcome.
Outcome: This is an action that comes from a condition being true or false.
Lesson outline: Using conditions to build quiz questions.
Today's lesson is split into two sections.
In the first section, we'll predict outcomes from user answers.
And in the second section, we'll use selection to control a programme.
Let's get started with the first section, predict outcomes from user answers.
What is selection? Pause the video and have a quick think.
Sam says, "Selection is part of a programme where if a condition is met, then a set of commands is run." If we take a little look here at the code in Scratch, we can read through it.
We've got when green flag clicked, that's the event block to trigger the action to start.
We have the forever loop.
This means that whatever's within the forever loop will be running continuously.
If key a pressed, then turn clockwise 15 degrees.
Here we can see the selection.
We've got the if/then block.
If key a pressed? Then turn clockwise 15 degrees.
The condition is, is the a key pressed, yes or no? If yes, then the sprite will turn 15 degrees clockwise.
If no, the computer programme will move on to the next set of instructions.
Look at this algorithm.
Ask, what is the capital of France? If the answer is Paris, then say, "Correct." If the answer is not Paris, then say, "Wrong answer." In this algorithm we have an example of selection.
The condition is, is the answer Paris, true or false? If the answer is Paris, then we'll say, "Correct." If the answer is not Paris, then we'll say, "Wrong answer." In this situation, we have an example of the if/then/else structure.
When we make decisions, we follow a flow.
This can help us to find out information, categorise objects, or determine the flow of a programme.
This is a branching algorithm.
It is an example of decision making flow.
Ask, what is the capital of France? Answer is Paris.
If it's true, Paris, then say, "Correct." And if it's false, not Paris, say, "Wrong answer." Jacob is following the branching algorithm.
Here's Jacob.
Jacob says, "What is the capital of France?" That's our question.
What is the capital of France? The condition is if the answer is Paris, it could be even true or false.
In this situation, there's only one correct answer to this question, it's Paris.
That's our condition.
Answer Is Paris, true or false? Aisha says "Paris!" Because the condition is true, Jacob says, "Correct." Our outcome, if true, is say "Correct!" Andeep says, "Madrid!" What will Jacob's reply be? Pause, video and have a quick think.
Because the condition is false, Jacob says, "Wrong answer!" Outcome if false, say "Wrong answer!" A branching algorithm makes it easier to identify the outcomes that will be carried out when the condition is true or false, because they've been separated into two parts, the condition creates two possible outcomes from one question.
Branching algorithms can be used to plan question flow in a programme.
This is useful when planning quizzes or other programmes that use conditions.
What is the condition in this branching algorithm? I'd like you to take a little look at the branching algorithm and see if you can work out the condition.
Let's read through it.
Ask: "What is the capital of Portugal?" The answer is Lisbon.
If that is correct and true, Lisbon, then say, "Well done!" If that is not correct and false, not Lisbon, say "Incorrect!" Pause the video and see if you can work out the condition.
Well done for having a go.
The condition is answer is Lisbon.
If it is true, there'll be an outcome which is "Well done!" and if it's false, then the outcome is say: "Incorrect!" So the answer to the question will be either true or false.
This wouldn't work If there was a question such as where would you like to go on holiday? With the question, where would you like to go on holiday has many different answers.
I might like to go to Madrid, whereas someone else might like to go to Paris.
There's no true or false answer in that question.
Sam wrote a branching algorithm for a sum.
Ask: "What is four times three?" In this example, there is one definitive answer and that answer is 12.
If the player gets the question right and says 12, we should say, "correct." If the player gets the question wrong and says any other number other than 12, we should say, "incorrect." Sam used the algorithm to create this code sequence.
Let's take a look through it.
We have an event block, when this sprite clicked.
We have a question, ask, what is four times three, and wait.
We have our condition.
Answer equals 12, true or false? If the answer equals 12, then say correct for two seconds.
That's our outcome if true.
Else, say incorrect for two seconds and that's our outcome if false.
Aisha says, "Does this code sequence need an infinite loop to keep checking the condition?" What do you think? Pause and have a quick think.
No, not in this case.
The 'and wait' part of the question block will wait until the question is answered and then move on.
Fantastic.
You've done so well.
I've got a task here for you.
Open the programme flow project on oak.
link/program-flow.
Number one, test a programme by typing in five different answers to the question.
One of your answers must be 12 and you can choose the other four answers.
Pause a video to finish the task.
I have a task here for you.
Fill in the table with your answers and whether the outcomes were the true response or the false response.
Pause the video to finish the task.
I'd like to give you some feedback on that.
Here is my table, answer is 12.
The outcome was false and I wrote that in words.
The answer was 12 in numerals and the outcome was true.
The answer was yes, and that was false.
The answer was 10 plus two, and that was false.
The answer was one, and that was false.
In this case, the only answer that's true is 12 in numerals and that's because it matches our condition exactly.
I have a task here for you.
Number three: Write one or two short sentences to explain what you found out about the question, condition and answer.
Pause the video to finish the task.
I'd like to give you some feedback.
The answer has to match the condition in the code exactly or else the outcome will always be false.
Even if the meaning is the same, the spelling must match for the condition to be true.
Fantastic.
You've done so well on the first part of today's lesson, predict outcomes from user answers.
Let's move on to the second section.
Use selection to control a programme.
Selection allows a programme to follow different paths based on an answer.
In Scratch, you can build programmes that respond differently depending on what the user inputs.
This programme shows what an algorithm needs to include.
Let's take a little look at the blocks here in Scratch.
When this sprite clicked, ask, do you like cheese, and wait.
If answer equals yes, then say, "great" for two seconds or else, "say more for me" for two seconds.
Here we've got one question.
Do you like cheese? And this question has a true or false response.
We have a clear condition, the answer equals yes.
This is the condition that the outcomes will be compared against.
This is our true outcome, so if the player inputs yes, the programme will say, "great" for two seconds.
And this is our false outcome, so if the player says anything other than yes, then it'll say, "more for me" for two seconds.
Let's imagine that the player inputs the words definitely.
In this case, the false outcome will be shown because it doesn't match the condition.
To create a quiz question in Scratch, you will need an event block to trigger the start of the programme.
Here's one, when this sprite clicked, and the ask and wait block to let you ask the question.
This is what it looks like here in blue.
The answer block will be the value of exactly how the user typed it.
It fits inside an equals operation block.
You set the condition in this space.
It fits inside the hexagonal shape inside an if/then/else block.
I have a question here for you, why do you use an if/then/else block? Pause the video and have a quick think.
Is that for A, to use selection, B, to use repetition, or C, to use events? The answer's A, to use selection.
Which of these blocks checks what the user types in as an answer? Is it A, answer equals? Is it B, if, then, else? Or is it C, when this sprite clicked? Pause the video and have a go.
The answer is A, answer equals.
Make sure you have an outcome for true and an outcome for false.
True: The answer needs to match the condition exactly to get this outcome.
False: Every other answer we set is false.
Which input will result in a true outcome? Do you think it'll be A, yeah, B, no, or C, yes? Pause the video and have a quick think.
Here, it's C, yes.
The user's input needs to be an exact match to what you put in the condition.
So even though A, yeah, does mean the person likes cheese, it doesn't match the condition, which is yes, Y-E-S.
The words and the spelling must be the same.
Debugging tips: Andeep says, "If your code doesn't work as expected, check If the answer is typed exactly as it is in the condition." Sam says, "Check you're using an if/then/block in your programme and that you have both outcomes." You're doing really, really well.
I've got a little task here for you.
Use selection to control a programme.
Number one, use a branching algorithm to plan a question and answer programme.
You must have one question, one clear condition, two outcomes, one outcome for true and one outcome for false.
Pause the video to finish the task.
I'd like to give you some feedback.
Number one, you may have designed: Ask, "Do you like cheese?" Answer is yes.
Let's look at the true outcome.
I'll follow the green arrow.
True (Yes.
) Say: "Great!" Let's look at the false outcome.
I'll follow the red arrow.
False (not Yes.
) Say: "More for me!" That's fantastic listening.
I've got another task here for you.
Number two, open the Bat question project on oak.
link/bat-question.
Use your branching algorithm to code your question and answer programme.
The bat sprite has some helpful code blocks that you should use as part of your programme.
Pause the video to finish the task.
I'd like to give you some feedback.
Let's take a little look at the code.
When this sprite clicked, ask, Do you like cheese, and wait.
If answer equals yes, then say, "Great," for two seconds.
Or else say, "More for me," for two seconds.
Wonderful, you've done so well in today's lesson.
Let's summarise.
Using conditions to build quiz questions.
Programmes can use selection to respond differently depending on a user's answer to a question.
You can use the ask and wait block and if/then/else blocks in Scratch to create branching programmes where condition leads to one of two outcomes.
A branching algorithm is helpful to plan these types of programmes because it's easier to see the two outcomes.