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 program.

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 program that uses selection using a set of project requirements.

Shall we make a start? We will be exploring these key words 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 program requirements and then we'll move on to build a program that meets requirements.

Let's make a start by interpreting program requirements.

Software engineers design, build, and test computer programs. A software engineer can typically earn between £30,000 and £70,000 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 program requirements and have to turn these into working programs. These requirements outline what the program should do and how it should behave.

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

Other times, the designer may be given a flowchart or pseudocode to interpret into program code.

When developing a program, 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 program 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 program 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 program.

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 program.

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 because we're going to input their guess.

Identify which are outputs from the joke machine program.

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're now moving on to the second part of today's lesson where we're going to build a program 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 program, 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 key words that we've used so far this unit.

Can you unscramble the key words? 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.

Initialize 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've 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 program.

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 programs? Well done.

Here is a solution in code.

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

Hopefully, you manage to add more jokes to your program.

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 1, I'm initiating the variable score to 0.

And then on lines 3 through to 6, 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 7, I store the user's input as punchline and I'm using the lower method here to convert their answer to case.

I then have a selection statement on line 8, 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 1.

So, we're adding 1 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're 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 summarize what we have learned together.

Software engineers are often given a set of project requirements that they have to turn into program 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.