I am trying to create a chessboard using nested loops with Python. I am having a hard time figuring out how to fill specific boxes with black and how to create 64 boxes. My coding so far is:
import turtle
t = turtle.Turtle()
t.speed(0)
t.penup()
t.goto(0, 0)
t.pendown()
for j in range(-150, 100, 50):
for i in range(-150, 150, 50):
t.penup()
t.goto(i, j)
t.pendown()
t.begin_fill()
for k in range(4):
t.forward(50)
t.left(90)
t.color("black")
t.end_fill()
for j in range(-100, 150, 50):
for i in range(-100, 150, 50):
t.penup()
t.goto(i, j)
t.pendown()
t.begin_fill()
for k in range(4):
t.forward(50)
t.left(90)
t.end_fill()
t.hideturtle()
turtle.done()
This will do the trick:
EDIT: this code doesn't use the
drawSquare
method