1

For example:

import turtle

num = 1
for i in range (10):
    num = turtle.Turtle()
    num += 1

I want to make 10 turtles named from 1 to 10. A code like this just makes one turtle called num before kicking up an error (TypeError: unsupported operand type(s) for +=: 'Turtle' and 'int'). Is there a way to make the 10 turtles named from 1 to 10 without manually defining them all?

Jalco28
  • 45
  • 5

3 Answers3

1
num = []
for i in range (10):
    num.append(turtle.Turtle())

?

Błotosmętek
  • 12,717
  • 19
  • 29
0
import turtle

# Create a list of turtles
turtles = [turtle.Turtle() for _ in range(10)]
MeBex
  • 488
  • 1
  • 5
  • 20
-1

Instead of num = 1, it should be num = 0, but appending works better because num is just simply counting in this case and doesn't have a relationship with num = turtle.Turtle().