user7529618 user7529618 - 4 years ago 141
Python Question

How do you make a list of turtles in python?

I'm trying to make a list of turtles and then use append to extend the list and add more turtles. I keep getting t does not support indexing if I attempt to declare t as a list and call it and if I try to use append, my program freezes. I'm using
Things I've tried so far:

t = [turtle.Turtle(),turtle.Turtle()]

t = turtle.Turtle[2]


None of these have worked.

Edit: I just realized my error and now I feel dumb. just 20 lines down from

t = [turtle.Turtle(),turtle.Turtle()]

I had the variable declaration:

t = 3000

Answer Source

Try something like this to make your turtles:

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import turtle
>>> turtle.resetscreen()
>>> turtles = []
>>> for _ in range(10):

>>> for offset, my_turtle in enumerate(turtles):
    my_turtle.right(offset * 10)


The example shows how to create ten turtles, how to rotate them, and how to move them forward.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download