video

Lesson video

In progress...

Loading...

Hello, welcome to lesson three of the selection in quizzes, the unit.

My name is Josh, I'm your computing teacher.

And in this lesson, we're going to look at asking questions and how questions can affect the flow of our programmes.

You all going to be using the scratch website so make sure you have access to a web browser.

If you're under the age of 13 remember you will need a teacher, parent, or carer to help you set up an account if you would like one.

You don't have to have an account but remember to download your projects after each task or after each lesson to ensure that you have them for future reference.

You will also need something to write on and with so make sure you've got those to hand.

If you've got all those bits ready let's crack on with lesson three.

So in lesson three, you're going to be able to explain how selection can direct the flow of a programme.

In order to do that, you're going to be able to explain that programme flow can branch according to a condition.

You're going to design a flow programme using the if-then-else structure.

And you're are going to show you that a condition can direct programme flow in one of two ways.

So on the screen, you have algorithms in action.

You have a question and you have two different outcomes.

You've got outcome if Paris is said.

So if the answer is true.

And the outcome if it's not Paris that's given.

It's laid out in a very linear fashion and it's quite difficult to understand what would happen if someone was wrong because you have to skip the correct part first.

So what we can look at it like is a branching structure which is very similar to the branching databases.

Now you've got your question at the top.

We have our condition in a sentence so the answer is Paris.

That's our condition.

And then it branches two ways.

You've got true, so the answer given is Paris, and false the answer given it's not Paris.

And you've got your outcome.

If it's true, which is say, correct.

And you've got your outcome if it's false which is say wrong answer.

And this is very much the way that the structure works using the if and else block.

So you have your condition if it's false the outcome is this, if it's true the outcome is this.

I branch, just like that.

And it's very it's much easier to see which way you are going to go down that branching root.

What we have on the screen now there is a programme.

For the question what is three times four? pause the video and see if you can identify the condition, the outcome if it's true, the outcome if false and anything else you can spot in this programme.

So hopefully you've had enough time then to think about where the condition is where the outcomes are and anything else you've managed to spot in our programme.

So we have our question, which is what is four times three? We have the wait part of that command block as well.

Now wait means that we don't need to use an infinite loop because the programme is designed to wait for an answer.

So we don't need any repetition in there because of that wait part of that block.

We've got our condition The answer is the same as 12 so answer equals 12.

We've got an outcome if the condition is true just say say correct.

And we've got outcome if the condition is false.

And that is using that same branch structure that we looked at on the previous slide.

So let's have a quick look at what that will look like.

As you can see, we've got our condition, the answer and we've got equals 12.

So let's have a look at some user inputs and see where they would fit into our true false columns.

So the first answer, the first user input is 12.

And you can see that the answer equals 12 so that would be true.

The next user input is eight.

We know that's incorrect so that would be false, look good on that false path.

We've got the user input equals 15.

Again, that's going to be false it's not the answer equals 12.

We have the input equals yes.

Again, it doesn't equal 12 it's not going to go down that true column because it's false.

And final one user input equals 12.

Now this one is really important because we all know that that is the written word for the number 12.

So technically the answer is right, but the programme doesn't know that because we specified that the programme should be looking for 12 the number and not 12 the word.

So four times three equals 12 and that's correct.

It's still going to go down that first column because the computer programme doesn't know that that is a correct answer.

So it all comes down to the answers that we give and the conditions that we say are going to be the correct answer.

So it's really important that we have those things in mind when we're moving through our selection and quizzes unit.

So we're going to hook out what happens if conditions or true false.

So on the screen, you've got a programme on the left hand side and you've got two outcomes.

You've got A and B.

Pause the video decide which one would happen if the condition is true and make a note of it on some paper or on some notes somewhere okay, because you will need that for your first task.

Suppose the video, have a go at doing that now resume the video when you're done.

Welcome back.

As I said, we are going to be using this for our tasks so we not going to go through the answers just yet.

Here is another one I'd like you to write down the answer too what will happen if the condition is true, pause the video, write down A or B.

It might be worth writing down exactly what will happen so that you have that knowledge and not just the A or B, because we won't be able to show these slides again.

So pause the video have a go at this one.

As before, we're not going to show the answers just yet, 'cause you aren't going to be testing these in a little while.

Final one then, what happens if the condition is false? Pause, the video decide if it's A or B, make a note of those of the actions, the outcome and resume the video when you're done.

Okay, welcome back.

As I mentioned, we're not going through the answers just yet because your first task is to have a go at running the programmes, running the codes, and checking your answers against what will actually happen.

Okay, so open up P5b3-1 have a go running those codes, checking what happens to each of them and see how you go on with that.

Pause the video? Resume it when you're done.

Hopefully you had a bit of time then to have a go at those codes, run them, see what happens check the answers that you'd written down and make sure that you had identified correctly.

What would happen if the conditions were true for the one and two and what would happen if the condition is false for the third one? So we're going to go through the answers together and see the outcomes that happen based on the user input.

So for the first one, we were looking to find out what would happen if the condition was true.

And if we read through the code we can see that the condition is touching dinosaur four.

And if that's true, then we will say, oops, for one second and that is A, as you can see there.

So if the sprite, is the scratch sprite is touching the dinosaur he's going to say, oops, for four seconds.

That is if the condition was true.

The next one then what happens if the condition is also true, we've got what's your favourite number? And if the answer given is 10, then what's going to happen.

As you can see, if we read through we've got turn clockwise 45 degrees wait one second and turn counter-clockwise 45 degrees.

So B is our answer for this one.

That's what's going to happen if the answer given to the condition is 10.

And the final one then is what will happen if the condition is false.

And you'll notice that that's not the same as the previous ones because it's looking at what will happen if the condition is not true, rather than when it is true.

Now, condition was left arrow key press and if that's not happening because of our thread loop we all going to be using the else part of our structure And that is going to be A, okay.

Next costume, wait one second.

Next costume, wait one second.

And with that forever loop that will continue to happen until the left arrow is pressed and it will continue to happen when the left hierarchy is released.

So that is the outcome that will happen when that condition is false.

So hopefully you were able to go through those programmes and you are going to understand what will happen at each junction each time the condition is either true or false and you were able to do that within the programme itself.

So we are going to look at designing outcomes.

On the screen we've got our algorithm that we looked at earlier and the way it is in our brunching structure.

Now we're going to create something similar to this algorithm.

The way you're going to do that is you're going to select a question that your sprite is going to ask you user.

And you're going to use an algorithm with a branching structure to identify the condition, the if part of our programme.

The outcome if the condition is true, the then part and the outcome.

If the condition is false the else part.

So on your worksheet you're going to have a table which has questions.

So you can select the question from the table and it's got outcomes so you can select your outcomes from the table as well.

So you can select an outcome if it's true, if the condition is true and an outcome if the condition is false you've also got your algorithm templates.

So you've got your branching template to use as well.

So if you have printed the resources off you can use that algorithm template to create your branching structure.

But if not, make sure you're drawing it out in the same fashion so that it's easy to see what will happen if your condition is true and what will happen if your condition is false.

So pause the video, have a go at creating your own algorithm and resuming the video when you're done.

Okay, welcome back.

Hopefully you had a bit of time then to create your own branching algorithm, and you were able to add a condition, add an outcome, sorry, if the condition was true you can add an outcome if the condition was false and you selected one of those questions from the table.

What we're going to do is we're just going to have a quick look at our own algorithms. And I want you to just to identify whether or not pausing the video briefly, whether or not it includes the question that will be asked to increase the condition, the outcome if the condition is true and the outcome if the condition is false, okay.

Just make sure you've got those so pause the video and make you've got those there because you're going to need them for the next part.

Okay, welcome back.

Hopefully you are able to identify those different parts in your own algorithm.

If you manage to notice that you've missed something make sure you were going back and just adding that in now because we all going to need it when we move on to our next step in this lesson.

So the next thing we are going to be doing is we're going to be implementing our algorithm as a programme.

So you're going to be doing this in the scratch website and we're going to need to make use of these command blocks we're going to use the, ask, something, and wait.

We're going to need to use the condition equals something, the answer equals something and we're going to need to use the, if, then else structure.

So how will you make use of these blocks when you're implementing your own algorithm? Let's jump into the Scratch programme and just have a quick brief look at how we can create and implement our own algorithms using the selection programme.

Here we're then in the Scratch programming software and let's just go through very quickly using some of those blocks to create a selection based programme which answers a question whether it's true or false with an outcome.

So the first thing we're going to need to do is just add an event block.

So when the green flag is pressed we then need to head on into the Sensing menu down here and we need to select our ask.

What's your name block? And we're just going to delete that question for now.

The next thing we're going to need to add is a control block or if then-else.

Remember we don't need the forever loop because we have our ask and wait.

So it's going to wait until the answer is given or the input is given.

We then need to find our block for a condition sort of to the Operator.

I'm going to use this equals here and add that in.

And we're going to go back to Sensing and we're going to find out answer block here.

So now ask something and wait if the answer given by the input of the user is equal to something then we can do the next step.

So we can look at what our condition, if it's true what outcome for that condition will be and what will happen if it's false.

So what will happen if the outcome is false? So we can do that by adding in say looks.

We could also add in turn we could add in move.

You can add in pretty much anything you'd like, okay what I'm going to do is I'm going to add in a move I'm going to say 50 steps and say done for two seconds.

If not my sprite is going to change costume, to costume two.

And it's going to turn clockwise 360 degrees.

So will end up back where he was.

So I'm going to put my question as would you like me to move across the screen? We have to be very careful here what we put in here because our answer needs to be exactly what the user input will be.

So we're going to say yes.

And then that is my programme ready to be tested.

So I'm going to test my programme now.

I'm going to press the red stop button first press the green button and you can see the most sprite is asking me would you like me to move across the screen? I'm going to say yes.

And he moved 50 steps across the screen.

So that's one way to implant and create your own programme using your algorithm.

So let's go back to the slides and see about your last task for this lesson.

The final task then is to implement your algorithm as a programme in the Scratch software.

Create a new programme and implement your own algorithm into that programme.

So you'll need to make sure you're making use of those blocks that we pointed out previously.

And you are creating your own programme with the outcomes that you selected.

Run it, test it, make sure it works and then resume the video when you're done.

Welcome back.

Hopefully you managed to create your programme, you implemented your programme using the algorithm and the branching structure that we discussed in the earlier part of this lesson, and you were able to make it work the way you wanted it to work.

So well done if you did, if you didn't feel free to explore pause the video again, go back and explore figure out how to make it work and then resume the video when you're done.

I've got a final thing to look at before we move on to the end of our lesson.

So pause the video and I want you to decide which way the inputs will force this programme to go.

So will it go down the true loop or will it go down the false loop.

So which outcome we'll have select based on the user inputs.

So, the first user input is 12.

Pause the video? Have a think? Which way is it going to go is it going to say correct, Or is it going to say wrong answer? Okay, welcome back.

Let's have a look at the next one.

Pause the video the answer given is 11 the input given is 11.

Is that going to say correct Or is it going to say wrong answer.

Pause the video and decide.

And then the final one then is the answer 11 as a word, pause the video, is it going to say correct or wrong answer? Welcome back.

So let's go through this together then.

So the first answer given is 12.

The question is what is four times three? Hopefully you know that four times three is 12, and the user has given the input 12.

However, if you look at the answer equals part our condition the answer equals 11.

So although four times three, sorry is 12 the answer in our condition is 11.

So it's going to say wrong answer.

And that's all based on that input given and the answer that's specified by the person who has programmed it.

So going back to that really important factor we need to make sure that what we're putting into our condition is correctly spelled is the correct answer, because then when people run their programme, we'll run the quiz in our example they're going to get the wrong answer even though they've given the correct one.

11 then if the number 11 is put in and that will give the correct answer.

Again it's not the right answer to the question but it is the correct condition answer.

So again, it's really important that we're making sure that our condition is correct before we share our programme.

And final one, as we mentioned earlier if we're using the word 11, it's not the same as our conditional answer our condition is 11, the number, so it's going to give the wrong answer.

So it's all about making sure that what we're writing into eye condition is correct in order for it to work as we expect it to work for our users.

So that is the end of lessons three and I hope you enjoyed implementing your algorithm as a programme and just working out how to ensure that the true and the false outcomes are correct and the answer in the condition is correct as well.

If you would like to share your work with us as always we would love to see it so consider doing that and ask your parent or carer to share on Instagram, Facebook, or Twitter, tagging @OakNational and #LearnwithOak.

I'm really looking forward to lesson four we're going to be moving on to designing our own quizzes.

So hopefully you are just as excited about that as I am.

And I really look forward to seeing you there.