Mar-21-2021, 05:42 AM
So I got this assignment and I am completely lost and stumped, it is supposed to draw 20 random circles in random sizes and random locations, I have to index the colors. What does that mean? I am doing it but it says bad color string. Also the count range is not counting how many circles there are, it is counting how many colors, and the 20 circles have to be 3 colors only, but the amount of circles on my code has to be the same as the amount of colors there are, so there can only be 3 circles. Please help me figure this out because it is very frustrating and I don't know how to use index for each color.
[sourcecode language="python" wraplines="false" collapse="false"]
import turtle
import time
from random import randint, choice
from turtle import Screen, Turtle
#variables
horizontal = int()
radius = int()
colors = ["red", "blue", "green","yellow"]
pen_size = int()
horizontal = 5
radius = 25
pen_size = 2
#loop to draw the circles
for count in range(0, 4):
#set the fill color, pen size and fill color
turtle.fillcolor(colors[count])
turtle.pensize(pen_size)
turtle.begin_fill()
#draw circle
turtle.circle(radius)
#reset location, radius and pen size
horizontal = horizontal + 75
radius = radius + 20
pen_size = pen_size + 2
#moving the turtle
turtle.penup()
turtle.goto(horizontal, 0)
turtle.pendown()
turtle.end_fill()
time.sleep(1)
turtle.reset()
turtle.write("Ready for more circles?", align = "center", font=("Arial", 16, "bold"))
time.sleep(3)
turtle.reset()
colors = ['red', 'green', 'blue']
#loop to draw the circles
radius = randint(10, 90)
vertical = randint(10,90)
horizontal = randint(10,90)
pen_size = randint(0,10)
#set the fill color, pen size and fill color
for count in range(0, 20):
turtle.fillcolor('blue'[1])
turtle.fillcolor(colors[count])
turtle.pensize(pen_size)
turtle.begin_fill()
#draw circle
turtle.circle(radius)
#reset location, radius and pen size
#moving the turtle
turtle.penup()
turtle.goto(horizontal, 0)
turtle.pendown()
turtle.end_fill()
time.sleep(1)
turtle.reset()
turtle.write("Ready for more circles?", align = "center", font=("Arial", 16, "bold"))
time.sleep(3)
turtle.reset()
[/sourcecode]
[sourcecode language="python" wraplines="false" collapse="false"]
import turtle
import time
from random import randint, choice
from turtle import Screen, Turtle
#variables
horizontal = int()
radius = int()
colors = ["red", "blue", "green","yellow"]
pen_size = int()
horizontal = 5
radius = 25
pen_size = 2
#loop to draw the circles
for count in range(0, 4):
#set the fill color, pen size and fill color
turtle.fillcolor(colors[count])
turtle.pensize(pen_size)
turtle.begin_fill()
#draw circle
turtle.circle(radius)
#reset location, radius and pen size
horizontal = horizontal + 75
radius = radius + 20
pen_size = pen_size + 2
#moving the turtle
turtle.penup()
turtle.goto(horizontal, 0)
turtle.pendown()
turtle.end_fill()
time.sleep(1)
turtle.reset()
turtle.write("Ready for more circles?", align = "center", font=("Arial", 16, "bold"))
time.sleep(3)
turtle.reset()
colors = ['red', 'green', 'blue']
#loop to draw the circles
radius = randint(10, 90)
vertical = randint(10,90)
horizontal = randint(10,90)
pen_size = randint(0,10)
#set the fill color, pen size and fill color
for count in range(0, 20):
turtle.fillcolor('blue'[1])
turtle.fillcolor(colors[count])
turtle.pensize(pen_size)
turtle.begin_fill()
#draw circle
turtle.circle(radius)
#reset location, radius and pen size
#moving the turtle
turtle.penup()
turtle.goto(horizontal, 0)
turtle.pendown()
turtle.end_fill()
time.sleep(1)
turtle.reset()
turtle.write("Ready for more circles?", align = "center", font=("Arial", 16, "bold"))
time.sleep(3)
turtle.reset()
[/sourcecode]