Python exercises for ages 10+

Render a checkerboard

Part 1

Using the below code as a starting point, create a function called createSquare that takes 4 arguments: x, y, size, and colour, such that createSquare(10, 10, 50, "white") draws a white square 50 pixels in height and width with its top-left corner at the coordinate (x, y).

from tkinter import *

c = Canvas(Tk(), width=500, height=500)

c.create_rectangle(10, 10, 60, 60, fill = "white")


Part 2

Using nested loops, draw a grid of 8x8 squares. Then, make the colour of these squares alternate such that you render a checkerboard pattern like the one below.

An 8x8 checkerboard pattern