video

Lesson video

In progress...

Loading...

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

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

Today, we're going to use our knowledge of selection to develop a programme.

Welcome to today's lesson from the Unit Programming Sequence.

This lesson is called Selection Challenge and by the end of today's lesson, you'll be able to build a programme that uses selection using a set of project requirements.

Shall we make a start? We will be exploring these keywords throughout today's lesson.

Project requirements.

Project requirements, the features, functions and tasks that need to be completed for a project.

Subproblem.

Subproblem, a smaller section of a wider problem that has been decomposed to make solving the problem easier.

Today's lesson is split into two parts.

We'll start by interpreting programme requirements and then we'll move on to build a programme that meets requirements.

Let's make a start by interpreting programme requirements.

Software engineers design, build and test computer programmes.

A software engineer can typically earn between 30,000 and 70,000 pounds a year depending on experience.

You can find out more about entry requirements and training for software engineer roles at oak.

link/software-engineer-job.

Software engineers are given programme requirements and have to turn these into working programmes.

These requirements outline what the programme should do and how it should behave.

Sometimes programme requirements may be provided in a document with a checklist of requirements.

Other times, the designer may be given a flow chart or pseudocode to interpret into programme code.

When developing a programme, it's sensible to break the larger problem down into smaller subproblems that can be solved independently.

This process is called decomposition.

You have been asked to develop a joke machine.

The joke machine is a programme that tests joke punchlines.

It gives the opening line to a joke and the user must guess the punchline.

If correct, the user wins a point.

The programme should include an introduction to the game, tell the start of the joke, allow the user to guess the punchline, check if the user is correct, give the user a point if they guess correctly, provide feedback if they guess correctly or incorrectly, and then reveal the final score at the end.

Here are some jokes that you'll include in your programme.

What is pink and fluffy? Pink fluff.

What is brown and sticky? A brown stick.

What is black, white, and red all over? A newspaper.

Time to check your understanding.

Identify which are inputs into the joke machine programme.

Look carefully at the list of requirements and identify which ones are inputs.

Pause the video whilst you have a think.

How did you get on? There's only one input into the system and that's where we allow the user to guess the punchline, 'cause we're going to input their guess.

Identify which are outputs from the joke machine programme.

Pause the video whilst you read the requirements carefully.

Did you manage to identify the outputs? Let's have a look at them together.

Including an introduction to the game will be an output.

Telling the start of the joke will be an output.

Providing feedback if they guess correctly or incorrectly will be output.

And then revealing the final score at the end is also an output.

Okay, we're moving on to our first task of today's lesson.

Using the list of project requirements, create a flowchart representation of the system.

This should help you code the solution later on.

The flowchart has been started for you.

Pause the video whilst you complete the activity.

How did you get on? Did You manage to create your flowcharts? Great work.

Here's a sample answer of the flowchart.

Note here, this is just a small part of the flowchart and you may have a different solution.

So we've got the Start at the top and then we are printing the message which says, Welcome to the joke machine.

Notice the parallelogram, which is used for input and output.

I then print, I'll tell you the start of the joke and you'll have to guess the punchline, some instructions to the user.

We're then printing the first part of the joke.

We then take the user's guess and store it as an input.

We then convert the user's input to lowercase.

Okay, we are now moving on to the second part of today's lesson where we are going to build a programme that meets requirements.

Now the problem has been broken down and the subproblems identified.

Each subproblem can be tackled individually.

So for example, we could start with this subproblem on the left.

For example, when asking for the punchline in the programme, you could break the task down into the following steps.

Write the opening statement to the first joke.

Create a variable to hold the user's guess.

Decide if you want the data to be converted to upper or lowercase and use the appropriate function for this.

Write an if statement that includes a condition to check if the punchline guess is correct.

Provide some text to display if they were correct.

And then test your code.

This can then be checked off one by one once they have been completed.

Time to check your understanding.

These are all keywords that we've used so far this unit.

Can you unscramble the keywords? Pause the video whilst you have a think.

How did you get on? The first word was selection.

The second word was condition.

The third word was flowchart, and the last word was variable.

Did you get all of those? Here is a list of subproblems for the score part of the joke machine, but they're not in the correct order.

Place the tasks in the correct order.

Pause the video whilst you have a think.

Here's the correct order.

Create a variable to track the score.

Initialise the variable at the top of the code, score = 0.

Increment the score within the if statement, score = score + 1.

Test your code by placing print score on a new line.

I'm sure you got the order correct there.

Well done.

Okay, we are now moving on to our final set of tasks for today's lesson.

Use the project checklist and your flowchart from Task A to build the joke machine programme.

Check off the subtasks as you go to keep track of your progress.

The project checklist can be downloaded as an additional resource from this lesson.

How did you get on? Did you manage to create your joke machine programmes? Well done.

Here is a solution in code.

Note that this is only the solution for the first joke.

Hopefully, you managed to add more jokes to your programme.

If you want to see the solution, you can go to oak.

link/joke-machine-solution.

Let's have a look at this code together.

So on line one, I'm initiating the variable score to zero, and then on lines three through to six, I'm printing out some instructions to the user.

So I'm welcoming them to the joke machine and then I'm giving them some instruction and then I'm asking them to guess the punchline and giving them the first line of the first joke.

On line seven, I store the user's input as punchline and I'm using the lower method here to convert their answer to lowercase.

I then have a selection statement on line eight, which says, if punchline == pink fluff, then we are going to print, Well done, you were correct.

And we are then on line 10, incrementing the score variable by one.

So we're adding one to their score.

On line 11, we have our else and line 12, the indented print statement which says, Wrong, it was pink fluff.

On line 14, we are printing out the user's score.

Remember, if you need to make any amendments to your code, you can always pause the video now and go back and do that.

Okay, we've come to the end of today's lesson and you've done a fantastic job, so well done.

Let's summarise what we have learned together.

Software engineers are often given a set of project requirements that they have to turn into programme code to develop a solution.

A larger problem is decomposed into smaller subproblems to make it easier to solve.

A flowchart or pseudocode is often used to design a system before it is created.

I hope you've enjoyed today's lesson and I hope you'll join me again soon.

Bye.