Preview lessons, content and tests

Computer Science & Programming solved. All in one platform.

1. To trial the platform and take tests, please take a few seconds to SIGN UP and SET UP FREE.

2. Searching for something specific? See our text overview of all tests. Scroll right for levels, and lists.

3. Student and Teacher User Guides |  Schemes of Work |   Real Teacher use Videos |


Join 36000+ teachers and students using TTIO.

Multiple Turtle Objects

Just like we can have many different integers in a program, we can have many turtles. Each of them is an independent object and we call each one an instance of the Turtle type (class). Each instance has its own attributes and methods — so alex might draw with a thin black pen and be at some position, while tess might be going in her own direction with a fat pink pen.

Code to try yourself (in the trinket below)

import turtle
wn = turtle.Screen() # Set up the window and its attributes
wn.bgcolor("lightgreen")

adam = turtle.Turtle()  #create adam and set some attributes
adam.color("hotpink")
adam.pensize(5)

eve = turtle.Turtle() # create eve

adam.forward(80) # Let adam draw an equilateral triangle
adam.left(120)
adam.forward(80)
adam.left(120)
adam.forward(80)
adam.left(120)  # complete the triangle

adam.right(180)  # turn adam around
adam.forward(80) # move him away from the origin

eve.forward(50)  # make eve draw a square
eve.left(90)
eve.forward(50)
eve.left(90)
eve.forward(50)
eve.left(90)
eve.forward(50)
eve.left(90)

wn.exitonclick()
 

Trinket

www.teachyourselfpython.com