Using the below code as a starting point, create a function called
createSquare that takes 4 arguments:
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.pack() c.create_rectangle(10, 10, 60, 60, fill = "white") mainloop()
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.
createSquaresfunction such that it takes a column and row index as an input (from 0 to 7 inclusive) instead of pixel coordinates
x % 2 == 0whenever
xis an even number. Further,
(row + column) % 2 == 0is true for all black squares where
columnare its row and column indices (from 0 to 7).