A Level Computer Science Python Turtle Worksheet

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 47

Computer Science– Year 11 -12 Summer Work

Year 11 Summer Work Computer Science

In order to complete the activities listed, you will need to: 


 Install Python https://www.python.org/downloads/ 
or  
 use the website  https://trinket.io/python  
o Delete and code you see inside the main.py file, or click the + to
create a new file 

Stage 1: Basic Shapes

Python is a text based programming language. Therefore watch out for


SYNTAX ERRORS!
We can import the turtle library to perform the same sort of effects as in
Scratch and Logo:
Import turtle

We can then call the turtle instructions in python:

Turtle.forward(10)
Turtle.rt(90)
Turtle.bk(100)
Turtle.Left(75)

 Open python
 Select File -> New File
 Type in your commands:
o You must start with import turtle and end with turtle.done()
 Select Run -> Run Module to run the program (you will need to save this to
your documents)
OR
 Use the website https://trinket.io/python to complete your work - Delete and
code you see inside the main.py file, or click the + to create a new file
Computer Science– Year 11 -12 Summer Work
Draw the following shapes in Python.

Take a screenshot of the code and how it looks on the screen


to show what you have done.
Developing Advancing Extension

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Insert Screenshot Here Explain how you solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Draw the following shapes in Python.
Take a screenshot of the code and how it looks on the screen
to show what you have done.

Developing Advancing Extension

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Insert Screenshot Here Explain how you solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Draw the following shapes in Python.


Take a screenshot of the code and how it looks on the screen
to show what you have done.

Developing Advancing Extension

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Insert Screenshot Here Explain how you solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Draw the following shapes in Python.


Take a screenshot of the code and how it looks on the screen
to show what you have done.

Developing Advancing Extension

Insert Screenshot of Shape Here Insert screen short of code here. Explain how you
solved the problem

 What code did you use?


 How did you work this out?
 What was easy or hard about it?
Insert Screenshot Here Computer Science– Year 11 -12Insert
Summer
screenWork
short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Extension Activity
Have a go at creating the additional images below

Advancing Extension

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Extension
Pick a language of your choice, and try and draw the images below:
Remember to copy across the code you create!

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Stage 2: Iteration (Loops)
There is no repeat command in python
Instead we must use Loops

There are two types of loop in python. A for loop, and a while loop:

For num in range (0,4):


turtle.fd(150)
turtle.rt(90)

number = 0;
While (number <4):
turtle.fd(150)
turtle.rt(90)
number = number + 1;

Both of these will produce a square of length 150.


Make sure for a While Loop that you increase the value of number, otherwise
the program won’t stop!

Notice the importance of whitespace!


We use the tab key to indent instructions which belong to a loop

Draw the following shapes in Logo. Make sure you use a Loop
Challenge: Use both types of loop (for loop, while loop)

You must start with import turtle, and end with Turtle.Done()

Take a screenshot of the code and how it looks on the screen


to show what you have done.

Open python
 Select File -> New File
 Type in your commands:
o You must start with import turtle and end with turtle.done()
 Select Run -> Run Module to run the program (you will need to save
this to your H Drive)
Computer Science– Year 11 -12 Summer Work

Insert Screenshot of Shape Here Insert screen short of code here. Explain how you
solved the problem

 What code did you use?


 How did you work this out?
 What was easy or hard about it?
Insert Screenshot Here Computer Science– Year 11 -12Insert
Summer
screenWork
short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Insert Screenshot of Shape Here Insert screen short of code here. Explain how you
solved the problem

 What code did you use?


 How did you work this out?
 What was easy or hard about it?
Insert Screenshot Here Computer Science– Year 11 -12Insert
Summer
screenWork
short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Insert Screenshot of Shape Here Insert screen short of code here. Explain how you
solved the problem

 What code did you use?


 How did you work this out?
 What was easy or hard about it?
Insert Screenshot Here Computer Science– Year 11 -12Insert
Summer
screenWork
short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Developing Advancing Extension

Insert Screenshot of Shape Here Insert screen short of code here. Explain how you
solved the problem

 What code did you use?


 How did you work this out?
 What was easy or hard about it?
Insert Screenshot Here Computer Science– Year 11 -12Insert
Summer
screenWork
short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Developing Advancing Extension

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Extension
Pick a language of your choice, and try and draw the Spirograph’s below, using
repeat within repeat functions
Make sure you screenshot your results!
Example of repeat within repeat
Create a square with an edge length of 50
In Logo: Repeat 4 [Fd 50 Rt 90]
Create 8 squares in a circle:
In Logo: Repeat 8 [Repeat 4 [Fd 50 rt 90] rt 45]

Create a hexagon with an edge of length 50


Create 30 Hexagons, so that they all form in a circle

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Create an Octagon with an edge of length 50
Create 90 Octagons, so that they all form a Half a circle

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?

Create a circle with edge length of 2

Create 12 circles so that they all form a circle.


Insert Screenshot Here Explain how you solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Extension:

Create your own! Right down the code you used and the finished
product

Try using large numbers for a repeat

(eg repeat 2384 [fd 76 rt 113] See what happens!


Insert Screenshot Here Explain how you solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Stage 3: Subprograms
Remember our code for loops it is either a for loop or a while loop:

For num in range (0,4):


Turtle.fd(150)
Turtle.rt(90)

Number = 0;
While (number <4):
Turtle.fd(150)
Turtle.rt(90)
Number = Number + 1;

We can create a subprogram in python to store a set of instructions so we can


use it multiple times

def square():
For num in range (0,4):
Turtle.fd(150)
Turtle.rt(90)

Like in Logo, we can pass a value into our


subprograms to change what happens when
we call it. We call these Parameters
Notice the importance of whitespace!
We use the tab key to indent
instructions which belong to a loop

Notice that the definition of the


subroutine comes before the main code!
If we don’t call the subprogram, nothing
will happen
Computer Science– Year 11 -12 Summer Work
Draw the following shapes in Python. Make sure you define your
subprograms!

Take a screenshot of the code and how it looks on the screen


to show what you have done.

Developing Advancing Extension

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Insert Screenshot Here Explain how you solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Take a screenshot of the code and how it looks on the screen


to show what you have done.
Developing Advancing Extension

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Insert Screenshot Here Explain how you solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Take a screenshot of the code and how it looks on the screen


to show what you have done.

Developing Advancing Extension

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Insert Screenshot Here Explain how you solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work
Remember to create subprograms for each of the shapes used in the image
For example, squares, circles, triangles etc

Developing Advancing Extension

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Developing Advancing Extension

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Insert screen short of code here. Explain how you
solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Subprograms: Extension
Can you make the image below using subprograms?

You will need to use the python commands below to make it easier:

 Pen up - turtle.pu()

 Pen Down - turtle.pd()

 turtle.bk(X)

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Stage 4: Variables
Remember our code for loops it is either a for loop or a while loop:

For num in range (0,4):


Turtle.fd(150)
Turtle.rt(90)

Number = 0;
While (number <4):
Turtle.fd(150)
Turtle.rt(90)
Number = Number + 1;
Remember our code for subprograms:

def square():
For num in range (0,4):
Turtle.fd(150)
Turtle.rt(90)

We can pass a value into our subprograms to change what happens when we
call it. We call these Parameters

def square(length):
for num in range (0,4):
turtle.fd(length)
turtle.rt(90)
Notice the importance of whitespace!
We use the tab key to indent
instructions which belong to a loop

Notice that the definition of the


subprogram or subroutine comes before
the main code!
If we don’t call the subprogram,
nothing will happen
Computer Science– Year 11 -12 Summer Work

Try and draw the shapes below. You will need to use variables to make the
code easier to draw
Take a screenshot of the code and how it looks on the screen
to show what you have done.
Advancing Extension

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?

Draw the following shapes in Python. Make sure you use variables

Take a screenshot of the code and how it looks on the screen


to show what you have done.
Advancing Extension
2X

X
Computer Science– Year 11 -12 Summer Work

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Take a screenshot of the code and how it looks on the screen


to show what you have done.

Advancing Extension

In the above, each hexagon gets bigger by 5, and you must right turn
before drawing the next hexagon.
You’ll need to use subprograms, variables and loops!
Insert Screenshot Here Explain how you solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Insert Screenshot Here Explain how you solved the problem


What code did you use?
How did you work this out?
What was easy or hard about it?
Computer Science– Year 11 -12 Summer Work

Variables: Extension
What are the rules to draw a shape with any number of sides?

 How many degrees are in a circle?

 What determines how many degrees you turn for a certain


shape?

Create a subprogram called polygon, which allows you to make a


multi sided shape with any number of sides (hint: you may need to
use the / symbol to divide)

Extension: Create a loop that increases the number of sides to create


the following image:

Remember to copy across the code you create!


Computer Science– Year 11 -12 Summer Work
Insert Screenshot Here Explain how you solved the problem
What code did you use?
How did you work this out?
What was easy or hard about it?

You might also like