Home > Mobile >  How can i get the output to print 10 circles instead of 9 in python turtle module
How can i get the output to print 10 circles instead of 9 in python turtle module

Time:07-03

I'm trying to figure out why my painting is not having the desired final outcome. As you can see, the first row is printing 10 circles but then the following rows are only printing 9. Have a look at my code, and the attached image.

from turtle import Turtle, Screen
import turtle
import random
 
colours = [(232, 251, 242), (198, 12, 32), (250, 237, 17), (39, 76, 189),
           (38, 217, 68), (238, 227, 5), (229, 159, 46), (27, 40, 157), (215, 74, 12), (15, 154, 16),
           (199, 14, 10), (242, 246, 252), (243, 33, 165), (229, 17, 121), (73, 9, 31), (60, 14, 8)]
 
turtle.colormode(255)
 
dot = Turtle()
dot.color(255,255,255) # Hide turtle trail
dot.setposition(-270, -350) # Starting position
dot.pensize(21)
dot.shape("circle")
dot.speed(60)
 
ypos = dot.ycor() # Y coordinates
 
for cycle in range(1, 11): # Cycles nested forloop 10 times
 
    for num in range(1, 11): # Create 10 circles
        dot.showturtle()
        dot.color(random.choice(colours))
        dot.forward(1)
        dot.penup()
        dot.forward(50)
        dot.pendown()
 
    dot.penup()
    dot.sety((ypos   40*cycle)) # moves turtle up one row with each iteration
    dot.setx(-270) # Sets the turtle to starting X coordinate with each iteration
 
dot.hideturtle()
 
screen = Screen()
screen.exitonclick()

enter image description here

  • Related