Skip to content
← Back to Community
For loop colors
Profile icon
ethanweinrot20

I am trying to use a for loop to create circles in python turtle and I want to change the color and size of the circle each time but I can't figure out how to change the color.

This is what I have:

import turtle

t = turtle.Turtle()

def colored_circle(color, radius):
move_from_center(radius)
t.color(color)
t.circle(radius)
move_from_center(-radius)

def move_from_center(distance):
t.penup()
t.right(90)
t.forward(distance)
t.left(90)
t.pendown()

colors = ['Red', 'Magenta', 'Orange', 'Black', 'Yellow']

for x in range (50):
colored_circle('Magneta', x)

Voters
Profile icon
MarwanAwad
Comments
hotnewtop
Profile icon
ash15khng

You could use something like import random then replace the 'Magenta' with random.choice(colors). That will pick a random colour.

Profile icon
ColePayneSexton

Screenshot_20210211-153407_Chrome

This should fix it

Profile icon
ColePayneSexton

At the end do
For i in range(number):
Draw()