def drawworm(wormcoords) for coord in wormcoords coord[' 'cellsize coord[' 'cellsize wormsegmentrect pygame rect(xycellsizecellsize pygame draw rect(displaysurfdarkgreenwormsegmentrect worminnersegmentrect pygame rect( cellsize cellsize pygame draw rect(displaysurfgreenworminnersegmentrectthe drawworm(function will draw green box for each of the segments of the worm' body the segments are passed in the wormcoords parameterwhich is list of dictionaries each with an 'xkey and 'ykey the for loop on line loops through each of the dictionary values in wormcoords because the grid coordinates take up the entire window and also begin pixelit is fairly easy to convert from grid coordinates to pixel coordinates line and simply multiply the coord[' 'and coord[' 'coordinate by the cellsize line creates rect object for the worm segment that will be passed to the pygame draw rect(function on line remember that each cell in the grid is cellsize in width and heightso that' what the size of the segment' rect object should be line draws dark green rectangle for the segment then on top of thisa smaller bright green rectangle is drawn this makes the worm look little nicer the inner bright green rectangle starts pixels to the right and pixels below the topleft corner of the cell the width and height of this rectangle are pixels less than the cell sizeso there will be pixel margin on the right and bottom sides as well def drawapple(coord) coord[' 'cellsize coord[' 'cellsize applerect pygame rect(xycellsizecellsize pygame draw rect(displaysurfredapplerectthe drawapple(function is very similar to drawworm()except since the red apple is just single rectangle that fills up the cellall the function needs to do is convert to pixel coordinates (which is what lines and do)create the rect object with the location and size of the apple (line )and then pass this rect object to the pygame draw rect(function def drawgrid() for in range( windowwidthcellsize)draw vertical lines