Solution Design There is a pattern to the colors of a chess board. If the column and row are both even or both
odd, then the space is white. If one is odd and the other is even, the space is black. Exercise #3, ―Odd
& Even‖ shows how the % modulo operator determines if a number (such as the one in the column
and row parameter) is even or odd. Use this to write a condition that determines if the oddness or
evenness of the column and row match.
Special Cases and Gotchas The function should first check whether the column or row argument is outside the 0 to 7 range
of valid values. If so, the function should immediately return a blank string.
Now try to write a solution based on the information in the previous sections. If you still have
trouble solving this exercise, read the Solution Template section for additional hints.
Solution Template Try to first write a solution from scratch. But if you have difficulty, you can use the following
partial program as a starting place. Copy the following code from https://invpy.com/chesscolor-template.py and paste it into your code editor. Replace the underscores with code to make a working program:
def getChessSquareColor(column, row):
# If the column and row is out of bounds, return a blank string: if column ____ or ____ > 8 or ____ < 1 or row ____:
return ''
# If the even/oddness of the column and row match, return 'white': if ____ % 2 == row % ____:
return 'white'
# If they don't match, then return 'black': else:
return 'black'
The complete solution for this exercise is given in Appendix A and https://invpy.com/chesscolor.py.
You can view each step of this program as it runs under a debugger at https://invpy.com/chesscolor- debug/.