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 program taken from the unit "Repetition in Programs." I'm really looking forward to learning with you today.

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

This lesson has three keywords.

The first keyword is debug.

Debug means to find and fix errors in a program.

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 program using an algorithm.

So that's our first learning cycle.

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

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 program is called debugging.

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

So here's his code.

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

And there's our error message.

We've got, "I don't know how to FWD." Logo is a program 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 we 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 recognizes.

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

So for example, fd space 100.

And you can see here that in Lucas's code there should be a space between rt and 90, and Lucas has an 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 when a mistake in a typing is stop 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 space 100, which moves the draws the line a hundred long, and then fd space 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 space 90, fd space 100, rt space 90, and fd space 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 space 90, rt space 180 and rt space 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 program.

So home is a really useful command.

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

You will then program 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 program.

Aisha says that "Planning helps you to organize your commands and make your program more accurate." And Jacob adds, "A clear plan will help the make the code easier to write and debug." So these are both really good ideas for why you should plan your program.

True or false, it's important to plan before coding so you can make a really complicated program? 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 program.

Which letters do you think will be a good choice to create in Logo? The letters that only have 90-degree angles in 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 letter that you are 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 program 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 value 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 a line 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 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 are going to follow an algorithm to write a program.

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

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

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

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

Then another turn, lt space 90.

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

Step five, lt space 90.

And finally step six, fd space 100.

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

So you have fd for forward, pk 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 program, 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 space 90 instead of lt space 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, bk 90 instead of bk space 90.

Those are both very common syntax errors.

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

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

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

Let's have a look at a question.

Which command has incorrect syntax? Is it A, fd 50; B, cs; or C, bk space 100? Well done.

The answer is fd 50.

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

Use your letter algorithm to guide your code.

Make sure to test your code and compare your finished program 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 space 90, ft space 100, 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 program more efficient.

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

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