Lesson video

In progress...

Loading...

Hi, my name's Mr. Hall and thank you for joining me for today's lesson, which is to create an algorithm for a text-based programme taken from the unit Repetition in Programmes.

I'm really looking forward to learning with you today.

The outcome of today's lesson is that you will create a programme in a text-based language.

This lesson has three keywords.

The first keyword is debug.

Debug means to find and fix errors in a programme.

The second keyword is syntax.

And syntax is the rules about how a programming language should be written.

And the third keyword is algorithm.

An algorithm is a precise set of steps that can be followed to do a task.

So there's our three keywords, debug, syntax, and algorithm.

Here's the lesson outline.

We've got two learning cycles in this lesson.

So first of all, you're going to plan a letter programme using an algorithm.

So that's our first learning cycle.

And then later on you're going to follow an algorithm to write a programme.

So let's get started with the first learning cycle.

Logo is a text-based programming language.

You use Logo to type commands that are drawn onto the screen.

So in this image we've got an example of FD 100, drawing a line which moves forward 100 spaces.

Lucas is trying to draw an L-shape in Logo.

So he says, "This is the shape I want to draw, and this is my code but it's not working." And you can tell it's not working because the program's returned an error.

So it says, "I don't know how to FWD." Let's see if we can work out what that means.

So finding and fixing errors in a programme is called debugging.

Let's look at Lucas's code to find the three errors.

So here's his code.

His code is rt 90, fwd 100, rt 90, and then fd 100.

And there's our error message.

We've got, "I don't how to FWD" Logo is a programme which you can use to draw lines and shapes.

When you type commands, it's important to be accurate and not make any mistakes.

Here are some of the commands that you can use in Logo.

So you have fd for forward, bk for backward, rt for right turn.

lt for left turn, cs for clear screen, pd for pen down, and pu for pen up.

So we can see that Lucas has used fwd 100.

This is not the correct command.

For forward, the command should be fd, so there's his first mistake.

So that's why we're getting the error message, "I don't know how to FWD," 'cause it's not the command which Logo recognises.

Many commands need a space after the command and then a number value.

So, for example, fd 100.

You can see here that, in Lucas's code, there should be a space between rt and 90, and Lucas hasn't included one.

So there's our second error.

Both of these errors are examples of syntax errors.

Syntax is the rules about how a programming language should be written.

Syntax errors are really common problems where a mistake in the typing has stopped the code working.

That's why it's really important to be accurate.

Logo uses steps as its value measurement.

The larger the number value, the longer the line drawn.

So you can see two examples here.

One of fd 100, which draws the line 100 long, and then fd 50, which draws the line 50 long.

So you can see the line for 100 is longer than the line for 50.

So Lucas has used forward FD 100 and this value is too small.

It should be 200 so that it is twice as long so he can get that L shape.

So now we debugged Lucas's code.

The errors are fixed and it will now run correctly.

So the correct code is rt 90, fd 100, rt 90, and fd 200.

And we've got that L shape that Lucas was looking for.

So let's have a look at a question.

Syntax is A, the programming language Logo, B, the rules about how a programming language should be written, or C, drawing with a screen turtle? Well done.

The correct answer is B syntax is the rules about how a programming language should be written.

The value after lt or rt is a degree of rotation.

So here we have rt 90, rt 180, and rt 270.

The number of value tells the turtle how much to turn.

A bigger number makes a wider turn and a smaller number makes a sharper turn.

And you can see on the diagram on the right of the screen that one turn is 90 degrees, two turns is 180 degrees, and three turns is 270 degrees in this example.

So each time, the amount of turn goes up by 90 degrees.

The home command is a way of moving the turtle back to the start while keeping the lines already drawn.

It also tells the turtle to point up.

So there's the command home.

This is helpful as you don't need to repeat commands that you've already typed to get back where you started.

Watch this animation demonstrating the commands pen up and home.

We'll start by moving the pen up, and then typing home, and the turtle's gone back to the home position and is pointing up, which is where it would begin before you run any of the programme.

So home is a really useful command.

In this lesson you'll create a plan to draw a letter.

You will then programme the letter shape in Logo.

So here we have some examples of how you might draw letters in Logo.

A plan can help you to think about what you want to include in your programme.

Aisha says that planning helps you to organise your commands and make your programme more accurate.

And Jacob adds, "A clear plan will help make the code easier to write and debug." So these are both really good ideas for why you should plan your programme.

True or false? It's important to plan before coding so you can make a really complicated programme.

Well done, that's false.

Let's have a look at why.

It's important to plan so you can think about what you want to include in your programme.

Which letters do you think will be a good choice to create in Logo? The letters that only have 90 degree angles of them will be a bit easier to create.

Some letters will be more challenging.

Some letters have 45 degree angles and some have other angles.

Now choose the that you're going to draw.

Once your letter is drawn on your grid paper, you will annotate your drawing.

Annotation means making notes around the drawing.

These notes will be part of your algorithm.

Alex asks, "What is an algorithm?" And Jacob says, "An algorithm is a precise sequence of steps that can be followed to do a task." Look at Aisha's algorithm for the letter P.

So she has a start here with an arrow, and then a series of instructions.

So first one, turn left 90, then number two, forward 100, and so on.

What could be improved about this algorithm? Well, the starting position is not really in a good position.

It means you would have to go back over a line that you've already drawn.

So if you start from where Aisha has started, you're gonna have to go back over that first line to get all the way around the P.

If the starting point was at the bottom of the letter, the letter P could be drawn without going back over any of the lines.

This would make your programme more efficient.

Think about where your starting point will be for the letter you've chosen.

When you start your annotation, you first show your starting point as well as the direction your turtle will start in.

So in this example, it's going to start at the top right-hand corner of the letter with the turtle pointing left.

To begin with, the turtle always starts pointing up.

So make sure you include a turn if you want to start drawing your first line in a different direction.

So here as we saw before, we're gonna start in a left direction for this one.

Then number your drawing steps.

So step one, turn left 90 to get the turtle pointing in the right direction.

Step two, forward 100.

Step three, turn left 90.

Step four, forward 200.

Step five, turn left 90.

And step six, forward 100.

Remember to include the values for length of line and 90-degree turns.

So here we have turn left 90 and forward 100.

You must include the values so you know exactly how far you want to turn and how long you want your line to be.

The steps Logo uses to move are quite small, so aligned value should be at least 100 or larger.

So now you're gonna plan your algorithm.

So number one, draw your chosen letter on the square grid and keep it as simple as possible.

Only use 90 degree turns if you can.

Draw your chosen letter on the square grid.

Now annotate your letter.

Make sure you include the starting position and direction, the directions and their lengths, and any turns and degrees.

And your instructions must be numbered.

Now annotate your letter.

So here's an example of an algorithm for the letter C.

We start from the top-right hand corner pointing left, and then the steps are, number one, turn left 90, number two, forward to 100, number three, turn left 90, number four, forward 200, number five, turn left 90, and number six forward 100.

So let's now move on to the second learning cycle.

Now you're going to follow an algorithm to write a programme.

Now that you have your algorithm, you can use it to create your Logo programme.

So there's an example of an algorithm that I showed you in the previous learning cycle.

So this is the algorithm to draw the letter C.

And you can see how the algorithm guides the programme.

So the first bit of code we're gonna have in the programme for the left turn 90 is lt 90.

Then we're gonna follow step two, which is forward 100, so the code fd 100.

Then another turn, lt 90.

Now onto step four, which the code is fd 200.

Step five, lt 90.

And finally, step six, fd 100.

These are the commands that you can use to create your programme.

So you have fd for forward, bk for backward, rt for right turn, lt for left turn, cs for clear screen, pu for pen up, pd for pen down, and home to return the turtle to the start position.

Fill in the blanks in these sentences.

The Logo command that resets a turtle to the starting position without removing drawn lines is called.

The command that stops the turtle drawing is called.

And the command that resets the turtle as well as clearing all the lines drawn is called.

Let's have a look at those answers.

So the Logo command that resets a turtle to the starting position without removing drawn lines is called home.

The command that stops the turtle drawing is called pen up or pu in the code.

And the command that resets the turtle as well as clearing all the drawn lines is called clear screen.

So the code is cs for that one.

If you find any mistakes in your programme, you will need to debug any errors.

Here's some examples of some common mistakes.

So you might use the wrong direction.

So you might use rt 90 instead of lt 90.

And watch out for any syntax errors.

Misspelling a command, so for example, using fwd for forward instead of fd, or for getting to put in a space.

So for example, bk90 instead of bk 90.

Those are both very common syntax errors.

Just because your programme runs, it doesn't mean there are no errors in it.

Even if a programme that runs can still be wrong if it doesn't match the intended outcome.

Checking your finished programme against your algorithm is important for accuracy.

Let's have a look at a question.

Which command has incorrect syntax? Is it A, fd50, B, cs, or C, bk 100? Well done.

The answer is fd50, and the syntax error there is that the space has not been included between FD and the number 50.

Now you can create your letter programme in Logo.

Use your letter algorithm to guide your code, make sure to test your code and compare your finished programme to the planned algorithm.

So here's an example with the algorithm and the code side by side.

So this is the algorithm on the left for the letter C.

So we start from the top right, and then we have a series of instructions going round right through to number six.

And that's our algorithm, so an annotated drawing.

And then the code for the algorithm is on the right-hand side.

So the code lt 90, ft 10, and so on.

Here's a summary of today's lesson.

An algorithm is a precise sequence of steps that can be followed to complete a task.

You can use an annotated design plan as an algorithm to guide your code.

A good start position can make your programme more efficient.

When coding, be careful of syntax errors, such as leaving out spaces, misspelling commands, or using the wrong direction.

Debug your programme to fix errors.

I hope you enjoyed this lesson and thank you for learning with me today.

I look forward to seeing you again in the future.