video

Lesson video

In progress...

Loading...

Hello, my name is Mrs. Halbro, and welcome to computing.

I'm so pleased you decided to join me for the lesson today.

In today's lesson, we are going to solve problems using programming constructs.

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 "problem solving using programming constructs", and by the end of today's lesson, you'll combine sequence, selection, and iteration, in a programme to solve a problem.

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.

Problem.

Problem.

A situation or task that needs to be solved.

Decomposition.

Decomposition.

Breaking down a task into smaller, more achievable steps.

Solution.

Solution.

A way in which a problem or task is solved.

There are two main parts to today's lesson.

We'll start with "analyse a problem", then we'll move on to "develop a solution".

Let's make a start with the first part of today's lesson, analyse a problem.

The programming constructs of sequence, selection, and iteration, can be combined to solve complex problems. Decomposition is the process of breaking down a complex task or problem into a sequence of simpler sub-problems. So you can see here, we've got the main problem that's been divided into three smaller sub-problems. Each of these sub-problems can then be looked at and solved separately, which makes it easier to solve the whole problem.

Okay, time to check your understanding.

Decomposition makes it more difficult to solve a problem.

Is this true or false? Pause your video here whilst you have a think.

Well done.

It's false.

Decomposition is the process of breaking down a complex task or problem into a sequence of simpler sub-problems, which makes it easier to solve the whole problem.

Okay, here's the problem we're going to be looking at during today's lesson.

JimBop is a dance game that requires the user to make Jim perform a dance move by pressing keys on the keyboard at the right time.

The programme has been started, but it needs to be completed.

Sofia is saying, "How could I use decomposition to break this problem down into smaller parts?" Ah, Sam's got a good idea.

"The problem could be broken down into dance moves.

Each dance move could be a separate subroutine.

A subroutine is how sub-problems are approached in programming." Okay, time for another check.

A large programme has been broken down into subroutines to make the problem more manageable to solve.

What is this process called? Is it A, problem solving? B, algorithmic thinking? Or C, decomposition? Pause your video here whilst you have a think.

Did you put C, decomposition? Great work.

The JimBop dance game has been broken down into three subroutines.

One for each move.

Move one, move two, and move three.

Okay.

It's now time for your first task of today's lesson.

The first subroutine, move1, for the JimBop dance game has been created.

Look carefully at the code blocks on the screen.

Explain what will happen when the user A presses the C key, and B presses any other key.

Pause the video here whilst you complete the activity.

How did you get on? You're doing a fantastic job so far, so well done.

The first subroutine, move1, for the JimBop dance game had been created.

You were asked what would happen when the C key was pressed.

Here's a sample answer.

"When the user presses the C key, the Jim sprite will switch to costume Jim-g." You were also asked what would happen when the user pressed any other key.

Here's a sample answer.

"When the user presses any other key, the Jim sprite will switch to the costume Jim-c, wait for one second, and then switch to the costume Jim-b." Okay.

Now for the second part of the task.

There should be two more dance moves in the programme.

Move2 needs the user to press two keys at the same time to start the dance move.

Move3 needs the user to press either one of two keys to start the dance move.

Use the table provided to plan out how the user will make Jim dance.

Pause the video here whilst you complete the activity.

For part two, you were asked to plan the moves for move2 and move3.

Here is a sample answer, but remember, you were asked to plan out your own design, so yours might look quite different.

Here, we've completed the table.

So for move2, the key that the user will press to start the dance move is Q and W.

If the user presses the correct key, then the costume is going to change to Jim-a.

If they press the incorrect key, then the costume is going to change to Jim-c.

For move three, the key that the user will press is one or nine.

If the user presses the correct key, then the costume will change to Jim-d.

If they press the incorrect key, then the costume will change to Jim-c.

We are now going to move on to the second part of today's lesson, where we're going to develop a solution.

A solution is a way in which a problem or task is solved.

There are normally multiple ways to solve a problem, and different solutions can be developed.

This is the same in programming.

A problem can be solved in different ways using different sequences of code.

Sometimes a solution can solve a problem, but it may not be the best or most efficient solution.

Testing and getting feedback on your solution is a good way to ensure that you've thought about all of the possible options, and what the best solution is.

Time for a check.

Fill in the gaps to complete the sentence.

There can be multiple ways to solve a (pauses) and different (pauses) can be developed.

Pause your video here whilst you fill in the gaps.

Great work.

There can be multiple ways to solve a problem, and different solutions can be developed.

This countdown has been created for the start of the JimBop dance game.

Is this the best solution? Look carefully at the code block and see if you can think of another solution.

Did you think of a different solution? This is not the most efficient way to create a countdown.

It could be improved by using iteration and a repeat block.

You are doing a great job so far, so well done.

We're now moving on to the final tasks of today's lesson.

Start by opening the programme oak.

link/JimBop.

Improve the countdown subroutine that you've just seen to make the solution more efficient.

There's a hint here.

You need to use the repeat block.

Pause the video here whilst you complete the activity.

Did you manage to improve the subroutine? Here's some sample code.

Underneath the defined countdown subroutine, we're setting the countdown variable to five.

We've then got a repeat block with the number five inside, which means it will repeat the code inside five times.

Inside the repeat block, we're saying countdown.

So the variable countdown for one second.

Then we're changing the variable countdown by -1, so we're taking one away from the value.

We then repeat that block five times, and then outside of the repeat block, we say dance for two seconds.

Let's see how the new improved countdown works.

So you can see that the countdown started at five and counted down by one each time the loop ran.

You are now going to use the plan you created for task A to create the subroutines for move2 and move3 in the JimBop game.

If you didn't manage to create a plan, you can use mine, which is on the screen now.

Pause the video here whilst you complete the activity.

Did you manage to complete the two new dance moves? Brilliant job.

Well done.

Here is some sample code for my solution.

So on the left hand side, I have the subroutine for move2.

I say to the user, press and hold Q and W, so the instructions for the dance move.

I then have a selection statement which says if the Q key and the W key are pressed, then switch the costume to Jim-a and wait one second.

If that's not the case, the else, we're going to switch the costume to Jim-c and wait one second.

And then when that selection or that block of code is completed, we're going to switch the costume to Jim-b.

Some key parts here, remember this was an and.

The user had to press both keys at the same time.

So it's important I've used the "and" code block here.

On the right hand side, I've got the subroutine for move3.

This time, I've got the instructions say, "press and hold one or nine", and then I've got my "if" selection statement, which says if the key one or key nine is pressed, then switch the costume to Jim-d and wait one second.

If it's not, then it's going to switch the costume to Jim-c and wait one second.

And then outside of that code block, so after that code has run, it's going to switch the costume to Jim-b.

Hopefully you managed to create something similar to this, and you've managed to create the dance game.

If you didn't quite get there, don't worry.

Pause the video here and try to recreate the code.

Okay, let's see how the final solution works.

You can see here that I've got all of the code completed in the scratch window.

So I've got the countdown subroutine that I've improved to make more efficient.

I've got the move1, which was already created.

And then I've got the move2 and move3 subroutines, which I've created.

Let's press play and see if we can make the programme work.

So here's the countdown.

Okay, so you should see that sometimes I pressed the key correctly and it made Jim move.

Sometimes I didn't, and it didn't move correctly.

Let's play it one more time.

We've come to the end of today's lesson, so well done.

You have worked so hard, and you have combined lots of programming constructs in a programme.

Let's summarise what we have learned today.

The programming constructs of sequence, selection, and iteration, can be combined to solve complex problems. Decomposition is the process of breaking down a problem into smaller, more manageable parts.

A problem can be solved using a variety of different solutions.

I hope to see you again soon.

Bye bye!.