video

Lesson video

In progress...

Loading...

Hi, I'm Becca, your computer teacher for the programming part two unit.

For this lesson, you're going to need your repl.

it account that you should have already set up with your parent's or carer's permission.

You're also going to need a pen and paper so that you can answer any of the questions and make notes as well.

And it'd be a really good idea to try and remove as many distractions as possible so that you can really focus in this lesson.

Once you've got all of that ready, we can begin.

In this lesson, you will use selection statements in a programme, you'll identify when selection statements should be used in programmes and you'll write and use expressions that use comparison operators.

To get started then, what I'd like you to do is take a look at these comparison operators.

And I want you to write down the purpose of each of those comparison operators.

See if you can remember anything from last lesson.

Pause the video while you have a go at that.

Excellent.

Let's take a look at the answers then.

So we had the first one, which means equal to.

Then we've got more than, lesser, not equal to, less than or equal to, and more than or equal to.

Now, the way I like to remember less than and more than is to look on the keyboard and the one on the left is less than, and that's how I remember it.

You might have your own way of remembering it but sometimes it's quite difficult to remember which one's less than and which ones more than.

So I look on my keyboard, I see the one on the left and that's less than.

Now, you're going to have a go at an activity now and it's about creating a joke machine.

And you're going to use the worksheet to help guide you through the creation of the joke machine programme.

And I'm going to go through that with you now as well, just to give you a bit of advice to how to use the worksheet too.

When you first look at the worksheet, you'll notice that you're given a scenario and I want you to make sure that you read that really, really carefully.

Cause that'll give you a good idea of how the joke programme actually works.

You've been given three jokes and these are the three jokes that are going to be included in the programme.

So you've got: What is pink and fluffy? Pink fluff.

What is Brown and sticky? A brown stick.

And what is black and white and red all over? A newspaper.

So those are three jokes that you're going to use in your joke machine.

You're then given some tasks and what I've done there is are first of all I've broken down those tasks that it takes the programme through step-by-step.

And then you'll notice that you'll see a tick list at the top.

So on that tick list, and you could write this down as well using your pen and paper if you want to, it says write texts that will output a message that introduces a user to the game.

It could include a title and some simple instructions.

So once you've done that you can just check it off your list and you might want to just put those three points and just check it off your list with your pen and paper as well.

I've also given you a sample block of code too, to help you with your programme.

So that just gives you a clue of the kind of programming construct that you're going to need.

So to display a message on the screen then you're going to have to use print view.

So for example, you might put print guess the punch line for example.

You've then got a common errors checklist as well.

So that's going to, if you'll get in lots of syntax errors when you're trying to programme this because I want you to make sure that you're testing as well as you go along, any syntax errors you get you can use that checklist to help you.

And then again as you work through, you're going to get ticks tick lists with different jobs for you to do, to complete the task.

You're going to get your sample blocker code and then you're going to get the common errors checklist as well.

Do you want to make sure that you follow those carefully.

Read the whole worksheet even before you get started so that you're really familiar with it.

Again, for keeping score.

Same thing, you're going to get tick lists, sample code, and a checklist.

And then as you get further along in the task, you're going to get less sort of help because hopefully the earlier bits would have helped you get started.

So then you'll see you don't get to a bit of a syntax example here or a code example for this one.

And then you get even less support there for that final bit at the end.

And then you just resume the video and come back when you're done with the worksheet.

So my advice really is when you're doing this task just making sure that you're reading that worksheet really, really carefully, using those checklists, using that sample code and making sure that you go through the syntax error checklist as well so that you really get all the support that you need to.

And then if after all of that, you still don't understand what you're going to do.

Then I'm going to go through the whole thing after this section with you, so that you can see exactly what you need to do.

If some bit you do struggle with, then you can just come come to the video and get a bit of support that way.

Now I've explained that worksheet a bit better for you.

Hopefully you can get on by yourself independently but just remember you can always come back and get support from my video that's coming up next.

Pause the video now while you have a go.

Excellent.

So I'm going to go through the solution with you now and I'm going to show you how I would programme it if it was me.

Now don't worry, If you haven't done it exactly the same as me as long as your program's working, then you've done it right.

You might have just done it in a slightly different way and that's okay.

Not all programme is the same.

We all do things differently and that's okay.

So you can follow along with me and see what I've done, see how I would've done it.

And that will helpfully help you give you little tips as well.

So if you were struggling a little bit there then you can get a bit of advice for how to do it yourself.

So let's see what I did in replica.

So this is going to be a live demonstration of how I would solve this joke machine problem if I was tackling it myself.

So I'm going to work it through.

I'm going to try and tell you my thinking as well as I went along.

And hopefully if you need any support as well you can use what I've been doing to help you with some of the code, if you need that bit of help.

So watch along code along with me as well.

If you, if you'd like to and let's get started.

So I've already read the scenario and I've looked at the jokes and then the first thing was task one.

Wasn't it? The introduction.

So it says, write texts that will output a message that introduces the user to the game.

It could include a title and some simple instructions.

Use the print statement to display the test to the user and test your code.

So I'm going to get started then.

So, whoops, I'm going to go to print.

Oh, I've done it wrong already.

Cause I haven't put a lowercase print.

So print.

welcome to the joke machine.

And then I'm going to have another line and it's going to say.

you will be given a.

The start of a joke.

Your job is to guess the punch line.

Okay.

I'm going to put that one-- it's a lower case Y.

I also just want to put something a little bit fancy or I think it's fancy.

It's just a little dotted line.

And delete that so it looks a bit more like a title and I'm going to run my programme.

Just make sure it works.

So welcome to the joke machine.

You will be given the start of a joke.

Your job is to guess the punchline.

So that's all working.

So I've done that task one.

There were no syntax errors, so I don't need to look at any syntax errors and then I can move on to task two.

The task two says write the opening statement to the first joke.

So, but, and I'm going to put a little space cause I like to separate things out in my code because it becomes much easier to read if I do that.

So the start of the first joke was what is pink and fluffy? There we go.

And so I've done that.

Create a variable to hold the user's guess.

So I'm going to use guess for my variable name.

Oh, here we go.

And it says decide if you want the data to be converted to uppercase or lowercase and use the appropriate function for this.

So I want guess and I want input and it's going to be in text, So I don't have to put, I don't have to cast to integer or anything like that.

So it actually is input, and I think I'm going to convert it to lowercase.

So I'm going to put lower.

It says, write an if statement that includes a condition to check if their punchline guess is correct.

So if guess is equal to, the answer is -- So it needs to be lowercase, doesn't it? Because I want it in lower case.

Pink fluff.

So if they say pink fluff, provide some texts to display if they are correct.

There we go.

Have I done it all? It says, test your code.

So I'm going to test it and I'm going to put pink fluff and it says, correct.

And I'm going to run it and I'm going to type something else and it didn't do anything cause I haven't got anything else there at this point in time.

So it's not going to say anything else.

So the task two now.

So then I'm going to look at the next one though.

So I didn't even look at the sample code that I've just realised.

I had some sample code as well to help me.

So you might have used that to, to help you.

And then the next one, task three, was keeping a score.

So it says create a variable to track the score.

Now I want the score at the very beginning to be zero at the start of the game.

So I'm actually going to put, score up here and I'm going to initialise it with the value zero.

So that's to get me started.

It says initialise the value at the top of the code, which I've done.

Increment the score within the if statement.

So score equal score plus one and test your code! And I can test it by printing the score.

So score equals score plus one.

And if I just put print score there, if I get it correct, it should be one.

So, pink fluff.

Yeah.

So now it's correct.

And my score is one, cause I've printed it there.

I'm just going to get rid of that.

Cause I don't need that in my actual code but it's always good to print your variables as you go along, because that helps you trace what the what is actually happening inside these variables.

So it's a really good way of testing your programme as you're going along.

So that's a really good idea.

So I've tested it, I'm ready.

And now onto the feedback one.

So task four.

So it says feedback for if they are correct.

Add an else underneath.

So underneath the if and add a print statement that provides feedback on the joke.

So test your code.

So I need another bit that says wrong, it was this punch line.

So, I can have else, print.

Wrong, it was pink fluff.

There we go.

So now I want to test it by getting it wrong.

It says, wrong it was pink fluff.

So that part's working also.

So then he says adding more jokes.

So it says, double check, your code is working correctly.

It should give feedback if they are correct to incorrect execute the programme, to check this, try each narrow which we'll do in a minute, add two new jokes to the programme, make sure that you test correctly.

So I have already tested it but I'm just going to test it again.

So what is pink and fluffy? If I put pink fluff, it says correct.

If I put a load of gobbledygook, it says wrong, it was pink fluff.

So I know now that this structure of this code works.

So instead of me typing all of this code again I can just copy and paste it for the other two jokes and just change the start joke and the punchline bit.

And this is great because it's more efficient because it's quicker for me to do it.

But also I'm less likely to make mistakes if I do it this way, because I know that block of code works and I'm just going to have to edit it.

Whereas if I typed it all out again I'm more likely to make syntax errors.

If I, if I tight type it all again from scratch.

So I'm just going to do control C to copy and then I'm going to leave a space.

Cause I like to leave a little space and I'm going to do my second one and I'm going to do my third one.

And did you notice there, that when I press the enter key, it still indents.

So I have to make sure I press back space so that it doesn't indent that time.

So now I've just got three jokes or that are exactly the same.

But if I go to my second joke, now I can put which one is it, let me just go back to my ___ So the second joke was.

what is brown and sticky? A brown stick, so.

I'm going to put there brown and sticky.

And then we've got a brown stick.

And then-- oh, and then I've got to change that bit as well.

I almost forgot that.

It was a brown stick.

And then the third joke was what is black and white and red all over? What is black and white.

whoops and red all over? And it was a newspaper.

And then wrong, it was a newspaper.

There we go.

So I've done all of that and now I need to make sure that I test it.

So I'm just checking that I've done everything right.

So yeah, make sure you test regularly.

I didn't test regularly then I probably should have tested it a bit more but I think I was pretty confident cause I copied and pasted it.

So what is pink and fluffy? It's pink fluff.

Correct.

What is brown and sticky? A brown stick.

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

So that's all working And if I get it all right, but what happens if I get it wrong? So wrong, it was pink fluff.

Wrong.

It was a brown stick.

And wrong.

It was a newspaper.

So it's working for both scenarios there.

And then finally it says revealing the final score.

So it says, use a print statement to reveal the final score to the user and test your code.

So I've just got to have a statement there that says what the score is.

So I could literally just have at the bottom, I could just have print score which would work, but that's quite boring.

If I put in an F string though, then what I can do is I can have.

your score is, and then use my curly brackets.

Like so.

And remember with replit, it always puts those two speech marks in at the end when you've got that variable at the end.

So I just have to go to the right one and delete that.

And then that gets rid of it.

So then I go run and this time I'm going to get one wrong.

So I'm going to do pink fluff and then I'm going to do gobbledygook and then I'm going to do newspaper.

So says correct.

And then it says your score is two.

So I've done it all.

So that is how you should have coded the solution.

Now you might have done it very slightly differently and that's absolutely fine if you did, as long as it's working.

But if you did struggle with some of that code, then you can just code along with me and you can do the solution with me and that's fine if you need to.

Awesome then.

So for your final task, what I'd like you to do is see if you can solve these anagrams. And these are all key words that have been used so far in this unit.

And also maybe in the part one unit too.

So see if you can solve the anagrams to see what the keywords are.

Pause the video while you have a go at that.

Let's have a look at the answers then.

So here's the answers.

You've got selection condition, flow chart, variable and translator.

Translator was less than one part once that was a long time ago that you used that word.

So that one might have been a tricky one for you.

Well then for this lesson, you've worked really, really hard to try and create your own joke machine.

And don't worry if you had to come to my video and get a bit of help, that's completely normal.

And you got to think, if you were in a classroom with a teacher then that teacher would be helping you all the time.

So it's only the same when I'm showing you videos to giving you a bit of help.

So don't worry if you had to get that extra little bit of support, you're all you're learning and that's okay.

It's all part of the process.

And if you'd like to please ask your parent or carer to share your work on Instagram, Facebook or Twitter, tagging at Oak national and hashtag learn with Oak.

Maybe you want to share your joke machine that you've done in this lesson.

That'd be great.

And I'll see you again.

Same for the next lesson.