Question
Asked Nov 17, 2019
9 views
Python-Coding-WHAT COLOUR SQUARE
PART 1 - Positions on a chess board are identified by a letter and number combination.  See diagram. The letter refers to the column and the number refers to the row :

** MUST USE IF / ELIF / ELSE or some version of it for full marks.  Do not use multiple IF statements unless you are nesting ***

Write a program that reads the position (row and column) and tells the user which colour it will be.  Do this twice.
For example, if the user enters g3 - it should tell you BLACK.  You can use the modulus for this question or lists - we have done similar work in this course.  Create a mathematical formula to work out the position and colour.
* The user should be able to input EITHER upper or lowercase.
check_circle

## Expert Answer

Step 1

Following is the python program which takes as input from user the position of chessboard. Check using if condition if the input given by user is incorrect format or not. Parse the two values of input separately and convert the first value to lower case, find its ASCII value and add it to the second value. If the sum of values comes out to be even, then print Black else print White.

Step 2

Code:

#loop to ask user to enter position of chess board two times

for i in range (0,2):

string = input("Enter position of chess board ")#prompt user to input position of chess board

while True:

#if user gives incorrect input then ask user to again enter the correct value

if (string[0].lower() > "h" or int(string[1]) > 8 or

len(string) != 2 or int(string[1]) == 0):

string = input("Please enter position correctly ")

&n...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in