
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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 −
Example
def solve(coordinate): if (ord(coordinate[0]))%2 == int(coordinate[1])%2: return False else: return True coordinate = "f5" print(solve(coordinate))
Input
"f5"
Output
True
- Related Articles
- How to find patterns in a chessboard using OpenCV Python?
- Program to find number of squares in a chessboard in C++
- Program to fill with color using floodfill operation in Python
- Program to count number of square submatrices with all ones using Python
- Program to partition color list in Python
- How to find the HSV values of a color using OpenCV Python?
- 8085 Program to find Square of a number using look up table
- How to Determine Last Friday’s Date using Python?
- Determine type of sound file using Python (sndhdr)
- Detection of a specific color(blue here) using OpenCV with Python?
- Python program to determine whether the given number is a Harshad Number
- Program to determine the minimum cost to build a given string in python
- Determine the type of an image using Python (imghdr)
- Color game using Tkinter in Python
- Transform to Chessboard in C++

Advertisements