import turtle import random def draw_polygon(sides, length, x, y, color): turtle.penup() turtle.setposition(x,y) turtle.pendown() turtle.color(color) turtle.begin_fill() for i in range(sides): turtle.forward(length) turtle.left(360//sides) turtle.end_fill() #end function draw_polygon() #Disable rendering to speed up drawing turtle.hideturtle() turtle.tracer() for i in range(10): sides = random.randrange(3,9) length = random.randrange(8, 40) x = random.randrange(-250, 251) y = random.randrange(-250, 251) color = random.choice(("cyan","coral","mediumblue","greenyellow","black","indigo","darkviolet")) draw_polygon(sides, length, x, y, color) #end for turtle.update() #render image turtle.exitonclick() #wait for mouse click