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.

In today's lesson, we're going to be looking at how we can write code to generate specific outputs.

We will also explore how the sequence code is written in can have an impact on programmes.

This lesson is called Developing Programmes Using Sequence.

And by the end of today's lesson, you'll be able to explain how sequence of a programme affects the output it produces.

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

Sequence.

Sequence.

The sequence of a programme is performed from top to bottom, executing each line in turn.

Debugging.

Debugging, the process of finding and correcting errors in programme code.

Look out for these keywords throughout today's lesson.

Today's lesson is split into two sections.

We'll start by writing code to generate specific outputs.

We'll then move on to explain sequence impact on programmes.

Let's make a start by writing code to generate specific outputs.

Integrated development environments, or IDEs, were created to give programmers all the tools they needed to write programmes in one place.

They allow you to write, run, and debug code without having to switch programmes.

They were designed to make programming easier.

What is the main reason IDEs were created? Is it A, to make computers run faster, B, to provide programmers with all the necessary tools to write programmes in one place, or C, to translate code into different languages.

Pause the video whilst you have a think.

That's right.

I knew you'd get that one.

The main reason IDEs were created was to provide programmers with all the necessary tools to write programmes in one place.

Precise instructions are very important when programming.

You also need to make sure that your code is written in the correct sequence.

A sequence of instructions will be read from top to bottom, performing each instruction in turn.

The following Python programme demonstrates sequence printing in order.

So you can see we have four lines of code with four print statements and we have, "This is line 1," "This is line 2," "This is line 3," and then, "This is line 4." The output appears in the same order as the instructions in the programme.

So you can see we have the four printed statements, "This is line 1," et cetera.

A karaoke programme has been created to help a class of nursery children remember the words to "Twinkle, Twinkle, Little Star." The following Python programme demonstrates sequence printing in order.

So we have print the first line of the nursery rhyme, which is twinkle, twinkle, little star.

And then we have another print line, which is the second line, which is how I wonder what you are, and so on.

The output appears in the same order as the instructions in the programme.

Time to check your understanding.

Why is it important to provide precise instructions when programming a computer? Is it A, computers can understand vague instructions, B, computers execute instructions exactly as they are given, or C, precise instructions make code shorter.

Pause the video whilst you have a think.

That's right.

It's important to provide precise instructions when programming a computer because computers execute instructions exactly as they are given.

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

And you're doing a fantastic job so far, so well done.

Using the Raspberry Pi Code Editor or another IDE, complete the following.

For part one, write a line of code that will output the text, "Hello World," on one line.

For part two, research and write the first four lines of the nursery rhyme "Humpty Dumpty." And then for part three, create a programme that outputs your morning routine.

For example, wake up, brush teeth, have breakfast, go to school.

Pause the video whilst you have a go at these activities.

How did you get on? Did you manage to write some code in your code editor? Brilliant, well done.

Let's have a look at some sample code together.

So for part one, you were asked to write a line of code that will output the text, "Hello World," on one line.

So we have the word print all lowercase, we open our brackets or parentheses, and then in speech marks we have the text, "Hello World." For part two, you were asked to research and write the first four lines of the nursery rhyme "Humpty Dumpty." So again, we have our print statements, we have our brackets, and we have our speech marks because we are displaying text or a string.

So the first line should be Humpty Dumpty sat on a wall.

The next line, Humpty Dumpty had a great fall.

Line 3, all the king's horses and all the king's men.

And then line 4, couldn't put Humpty together again.

For part three, you are asked to create a programme that outputs your morning routine.

So again, we have a sequence of print statements which will run from top to bottom.

In the first one I've put, "My morning routine:" On line 2, I have, "1.

Wake up," On line 3, "2.

Brush teeth," and so on.

Your morning routine may look different to this, but as long as you've got a sequence that printed out correctly, you've done a great job.

Well done.

Okay, we are now moving on to the second part of today's lesson, where we're going to explain sequence impact on programmes.

When you run a programme, it will be executed one statement at a time in the order that the statements are written.

If you've ever built a model or some flat-pack furniture, then you will have seen some precise instructions.

Having the instructions in the wrong order can produce incorrect results.

For example, these instructions for washing your hands are in the incorrect sequence: scrub your hands for at least 20 seconds, rinse the soap from your hands under clear, running water, rub your hands in the soap until all areas are covered, wet your hands with clean, running water, dispense soap into your hands.

Time to check your understanding.

What happens if the instructions in a sequence are in the wrong order? Is it A, the programme will run faster, B, the programme will produce unexpected or incorrect results, or C, the programme will automatically correct the order? Pause the video whilst you have a think.

That's right, the programme will produce unexpected or incorrect results.

Remember, the programme is only going to follow the instructions that we provide.

The following Python programme demonstrates sequencing by printing in order, but it is an incorrect sequence.

So you can see we have on the first line, "Up above the world so high," on the second line, "How I wonder what you are!" On line 3, "Twinkle, twinkle little star," And on line 4, "Like a diamond in the sky." The output appears in the same order as the instructions in the programme, which is the incorrect order.

Debugging is the process of finding and fixing errors in the programme.

Errors can prevent a programme from running or make it produce the wrong output.

Identifying the incorrect sequence of instructions is an important part of debugging.

Common mistakes like these are known as logic errors: displaying something before setting it, printing output before processing the data, and asking for user input after trying to use it.

So let's have a look at this snippet of code.

On line 1, we are printing a message using an f-string, which says, "Hello," and then it's going to display the value held in the variable user.

But there's a mistake here because we don't gather the user input until line 3 of this programme.

This will result in an error.

The correct sequence for this programme would be to start by printing the message, "What is your name?" Then taking in the user's input and storing it under the variable user, and then using the print statement with the f-string to print out the welcome message.

In Python, it's easy to make syntax errors, and all programmers make syntax errors.

Syntax errors can be frustrating when you start learning a text-based programming language like Python.

So here you can see I have a print statement and I have a syntax error.

Identify the syntax error in this code.

Is it A, a bracket is missing, is it B, print should have a capital P, or C, a speech mark is missing? Pause the video whilst you have a think.

That's right, a speech mark is missing at the end.

And a clue to this is that my IDE provides syntax highlighting.

So that closed bracket is appearing in green, which it shouldn't be, it should be white.

So that gives me a slight hint when I'm writing the code that I've actually missed the speech mark out there.

So look out for syntax highlighting, it can help you detect and correct syntax errors.

Okay, we're moving on to our last set of tasks for today's lesson, and you've done a fantastic job to get this far, so well done.

For part one, explain why this programme will not produce the intended output.

What type of error is present? For part two, describe the impact of the current order of instructions on the program's output? What will the programme actually display? And then for part three, I'd like you to write the corrected version of the code, placing the instructions in the correct order.

Pause the video whilst you have a go at the activity.

Finally, for part four, explain why the order of instructions is critical in a Python programme using an example and the concept of logic errors to support your explanation.

Pause the video whilst you answer the question.

How did you get on? Let's have a look at some sample answers together.

For part one, you were asked to explain why this programme will not produce the intended output.

What type of error is present? This programme will not produce the intended output because the messages are displayed in the wrong order.

This is a logic error as the programme runs but produces an incorrect sequence of messages.

For part two, you are asked to describe the impact of the current order of instructions on the program's output.

What will the programme actually display? This sequence doesn't make logical sense for a game.

The programme will display the messages in the following order: level completed!, game started, your score is 100, get ready.

You were then asked to write the corrected version of the code, placing the instructions in the correct order.

So on line 1, you should have the print statement with, "Get ready.

." On line 2, "Game started." On line 3, "Your score is 100." And line 4, "Level completed!" That makes much more sense.

Finally for part four, you were asked to explain why the order of instructions is critical in a Python programme using an example and the concept of logic errors to support your explanation.

The order of instructions in a Python programme is critical because the programme follows them one by one.

If the instructions are in the wrong order, the programme will do the wrong thing or give an incorrect result.

This is called a logic error.

For example, imagine a programme for a game.

If the programme shows the, "Game Over," message before the player has even started playing, it won't make sense.

The instructions must be in the correct order to make the game work properly.

Remember, if you need to pause the video here and add any extra detail to your answers, you can do that now.

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've learned in this lesson.

Computers follow the instructions in a programme in a specific order or sequence to generate output.

Changes to the sequence of code will affect the program's output.

Debugging is essential to ensure the code sequence is correct and produces the desired results.

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

Bye.