import turtle

def_cell_count = 8
def_cell_width = 25
def_cell_color = 'black'

min_cell_count = 1
min_cell_width = 9
valid_colors = ['black', 'red', 'green', 'blue']

bad_cell_count = False
bad_cell_width = False

try:
    cell_count = input('\nEnter number of cells in board: ').strip()
    cell_count = int(cell_count)

    if cell_count <= min_cell_count:
        raise ValueError('Less than minimum cell width')

except ValueError:
    bad_cell_count = True


try:
    cell_width = input('\nEnter the width of each cell: ').strip()
    cell_width = int(cell_width)

    if cell_width <= min_cell_width:
        raise ValueError('Less than minimum cell width')

except ValueError:
    bad_cell_width = True


cell_color = input('\nEnter the color ( ' + ' or '.join(valid_colors) + ' ): ').strip()


if bad_cell_count:
    print('\nWarning: Invalid number for the cells:', cell_count)
    print('Using default value of', def_cell_count, 'cells instead!')
    cell_count = def_cell_count

if bad_cell_width:
    print('\nWarning: Invalid number for the cells width:', cell_width)
    print('Using default value of', def_cell_width, 'instead!')
    cell_width = def_cell_width

if cell_color not in valid_colors:
    print('\nWarning: Invalid color for the cells:', cell_color)
    print('Using default color ' + def_cell_color + '!')
    cell_color = def_cell_color


# initializing board parameters
board_size = cell_width * cell_count
mandy = turtle.Turtle()
mandy.fillcolor(cell_color)
mandy.penup()
mandy.speed(0)
mandy.goto(-board_size / 2, -board_size / 2)

screen = turtle.Screen()
screen.setup(400, 400)

# stores whether the current cell to be colored or not
colored_cell = True

# loop to print cells
for row in range(cell_count):

    if cell_count % 2 == 0:
        colored_cell = not colored_cell

    for cell in range(cell_count):

        if colored_cell:
            mandy.begin_fill()

        for _ in range(4):
            mandy.fd(cell_width)
            mandy.lt(90)

        if colored_cell:
            mandy.end_fill()

        mandy.fd(cell_width)
        colored_cell = not colored_cell

    mandy.bk(board_size)
    mandy.lt(90)
    mandy.fd(cell_width)
    mandy.rt(90)

# drawing boundaries
mandy.pendown()
mandy.pencolor('black')
for _ in range(4):
    mandy.fd(board_size)
    mandy.rt(90)

# screen loop to maintain turtle window
turtle.mainloop()