jeudi 15 mars 2018

Adding named turtles in python list?

I am currently working on a mini project where user enters a number and that number of turtles are generated and race to the middle. The turtles were created through while statement and then each named after its color using a nested IF statement, is there anyway to make a list of these turtles or a way to add them into a list which i can use random function on for the race to ensure a random color moves every turn. I cant seem to make a list containing the turtles names. (below is simplified and focused version of my question)

import turtle
y = turtle.turtle()
Racers = []
if Z == "Blue":
    Blue = y
    Racers.append(Blue)
elif Z == "Yellow":
    Yellow = y
    Racers.append(Blue)
etc.

Aucun commentaire:

Enregistrer un commentaire