import turtle
def main():
turtle.pensize(4)
for x in range(5):
for y in range(5):
turtle.penup()
turtle.goto(x*50,y*50)
turtle.pendown()
if (x+y)%2 == 0:
turtle.begin_fill()
black_square(50)
turtle.end_fill()
else:
turtle.begin_fill()
white_square(50)
turtle.end_fill()
def black_square(width):
turtle.fillcolor('black')
for x in range(4):
turtle.forward(width)
turtle.left(90)
def white_square(width):
turtle.fillcolor('white')
for x in range(4):
turtle.forward(width)
turtle.right(90)
main()
Current image:

Intended image:

My code won't draw a correct checkerboard pattern, but I wonder why every for loop my square black and white both executed at the same time? I am not asking for the correct code that will get me the correct checkerboard and I just want an explanation for the mistakes in my code.
