In: Computer Science
write a graphical application that displays a checkerboard with 25 squares.(black and white only and run from pycharm.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
#code
import turtle
#creating a turtle, setting max speed
t=turtle.Turtle()
t.speed(0)
#number of columns, rows
cols=5
rows=5
#size of each square
size=60
#starting position
x=-150
y=150
#pen up
t.up()
#initial color - black
color='black'
#looping through each row and column
for i in range(rows):
for j in
range(cols):
#moving turtle to
x,y
t.goto(x, y)
#using current color
as fill color
t.fillcolor(color)
#start to fill
t.begin_fill()
#filling a
rectangular path
t.forward(size)
t.right(90)
t.forward(size)
t.right(90)
t.forward(size)
t.right(90)
t.forward(size)
t.right(90)
#end of fill
t.end_fill()
#moving x size
spaces forward
x+=size
#swapping colors
between black and white
if
color=='black':
color='white'
else:
color='black'
#resetting x to starting
position
x=-150
#updating y size spaces down
y-=size
#hiding turtle and finishing drawing
t.ht()
turtle.done()
#output