Program to determine color of a chessboard square using Python

Suppose we have a chessboard coordinate, that is a string that represents the coordinates of row and column of the chessboard. Below is a chessboard for your reference.

We have to check whether given cell is white or not, if white return true, otherwise return false.

So, if the input is like coordinate = "f5", then the output will be True (See the image)

To solve this, we will follow these steps −

  • if ASCII of coordinate[0] mod 2 is same coordinate[1]) mod 2, then

    • return False

  • otherwise,

    • return True

Let us see the following implementation to get better understanding −


 Live Demo

def solve(coordinate):
   if (ord(coordinate[0]))%2 == int(coordinate[1])%2:
      return False
      return True
coordinate = "f5"





Updated on: 29-May-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started