- [Craig] In this video, we take a look at Python's turtle module.
(uplifting piano jingle)
So, the specification states that students must be able to write programs
that use pre-existing, built-in, library subprograms,
and the programming language subset, PLS, document
goes on to list all of the Python modules and the associated subroutines,
which you're going to need to know for the paper two on-screen exam.
In this video, we take a look at the turtle module.
Turtle is a pre-installed Python library that enables users to create pictures and shapes
by providing them with a virtual canvas.
The on-screen virtual pen that you use for drawing is called the turtle,
and this is what gives the library its name.
The turtle library was originally included in Python as a way for new programmers to get a feel
for what programming with Python is like in a fun and interactive way.
To make use of the turtle module, you first must import it with the line import turtle.
When you start, the turtle begins at the canvas at coordinates zero zero,
and this is based on a standard X, Y coordinate system.
And this is the middle of the canvas, and the pen is considered down.
Now we're going to be using an abstract canvas on the right here
that has kind of like grey grid lines on.
You won't obviously see that when you actually run this in Python, it will be a blank canvas,
but it should make it easier for you to follow along and learn the basics.
To draw, you then issue the turtle commands.
For example, turtle dot forward 30 makes the turtle move forward 30 steps
and drawing the line behind it.
You can change the position of the turtle at any time with the command
turtle dot setpos, open brackets, X, comma, Y, brackets.
Assuming the turtle started at zero zero
and each square shown here is 10 steps by 10 steps,
then what do you think the following program would draw?
Pause the video and when you think you know, unpause and have a look.
You probably thought it would draw what we're showing you on the screen now.
What it actually draws, however, is this.
This is because we've not lifted the pen off the canvas
when we issued the turtle dot setpos commands.
We can lift the pen and place it down again with the commands
turtle dot penup and turtle dot pendown.
The following version of the program would give the desired output on the screen.
You can also change the pen colour and pen size with the commands
turtle dot pencolor and turtle dot pensize.
Here's the same program modified slightly to give the output shown.
You can also make the turtle go backwards in steps instead of forwards with turtle dot back.
What do you think the following program would do?
Again, pause the video, work it through
and when you think you know, unpause and see if you are right.
So this is what that program would have produced,
a mirror image of the first part.
Another handy command is turtle dot reset.
Like the name suggests, it clears the canvas,
it sets the turtle home to zero zero.
And it also resets variables to their default values like the pen colour and pen width.
We can also make the head of the pen rotate with the following commands,
turtle dot left or turtle dot right.
And then we specify the number in brackets in degrees.
How could we use, therefore,
turtle dot forward and turtle dot right or turtle dot left to draw a square?
You probably came up with some commands similar to that above.
Now that's all the different commands you need to know about for the exam.
But how could we make the above program slightly more efficient?
There is nothing stopping you using all the other programming constructs
you've learned about already.
So here we've included the turtle dot forward and turtle dot right commands
inside a for loop construct.
This has saved lots of unnecessary lines of code and achieves the same result.
You can end up combining all of these techniques
to make some very interesting geometric designs and patterns.
On the next two screens are a summary of all the commands you need to know about
from the turtle library along with their descriptions.
Pause the video and take some notes.
Here's the rest of the commands.
The only two we didn't show during this video were
turtle dot hide turtle and turtle dot show turtle.
But as the name suggests, all this simply does is turn off the actual visible arrow of the turtle
or make it visible again.
So that's the theory content of the video covered.
We're just going to spend a little bit of time talking about the programming language subset.
If you've heard this before,
you can skip the rest of this video.
Otherwise, it's definitely worth a quick watch.
So the exam board Edexcel have released a document that they call the programming language subset,
which you can see here on the right.
This document specifies which parts of Python 3 are required
in order that the assessment can be undertaken with confidence.
Students familiar with everything in this document
will be able to access all parts of the paper two on-screen assessment.
The exam board will not go beyond the scope of this document
when setting you any questions in the paper two exam.
Any students who do successfully use more complex methods which are not included in the document
will still, however, be awarded marks.
Further to this, you will see here from the front of the exam paper
that you are actually going to be supplied with a printed and an electronic copy of the PLS
during your paper two exam.
Well, if this document outlines everything you need to know
in order to program in Python during the exam
and you can be guaranteed that you can answer all the questions
using all the techniques in this document for full marks,
then you might as well get used to using it now.
Ask for a copy from your teacher
and have it as a reference guide at all times throughout your GCSE course.
It will be invaluable.
(uplifting piano jingle)