Asked Nov 17, 2019
Python Coding (on PyCharm Community Edition)
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.
ab cde f g h

Image Transcriptionclose

7 6 5 4 3 2 1 ab cde f g h


Expert Answer

Step 1

The approach and code of a python program to check whether the position of the square of a chessboard is black or white are given below:


  • Using a for loop to restrict the user to check the position of a square in the chessboard twice.
  • Inside the for loop, while loop is used to check for the condition is true.
  • Inside the while loop, if statement will check the input value is a combination of an alphabet and a number. Also, it will check that the alphabet does not exceed to h, and the number is equal to 8.  
  • In the ADD variable, the sum of ASCII value of the character and number is saved. Now, the ADD variable will be checked in the if-else statement.
  • Then if-else statement will check and return that the input value is positioning a white or black square in the chessboard.     
Step 2


#for loop is used to check the position of a square in the chessboard twice 

for i in range (0,2):

    #displaying message to prompt user to enter the value he wants to check

    STR = input("Please enter the value you want to chhess: ")

    while True:

        #if-else statement is used to check the entered value is in the scope or not

        if (STR[0].lower() > "h" or int(STR[1]) > 8 or len(STR) != 2 or int(STR[1]) == 0):

            #displaying message to prompt user to enter the correct value

            STR = input("Please enter the correct va...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

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.

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A

Q: Write a C++ program: A palindrome is a word that reads the same forwards and backwards for example "...

A: Program:#include<iostream>#include<bits/stdc++.h>using namespace std;void Palindrome_Che...


Q: How do I write a line of code in Java to find how many numbers are below and above average ?

A: ⦁ Create two variables in the main method and initialize them with zero.⦁ Iterate the all numbers wi...


Q: What is the main difference between WEP and WPA?

A: Wired Equivalent Privacy(WEP):WEP is the world's most popular Wi-Fi security protocol. It is part of...


Q: Write a loop that reads positive integers from standard input and that terminates when it reads an i...

A: Following is the loop which prints the sum of all even and odd integers entered by the user and will...


Q: Find the truth table that describes the following circuit.

A: The given circuit diagram shows operations for each gate. The final Boolean expression found through...


Q: d. Explain the steps of the fetch-decode-execute cycle. Your explanation should include what is happ...

A: Fetch-decode-execute cycle stepsFetch-decode-execute instruction cycle consists of three phases. The...


Q: Transient PopulationPopulations are affected by the birth and death rate, as well as the number of p...

A: Program:#include <iostream>using namespace std;double population(double P, double B, double D,...


Q: Given the follwing business rules, create an Crows Foot ERD.  The ERD must include all primary keys,...

A: The crow’s foot diagram shows the entities as the boxes and relationship as the lines between the en...


Q: A domain controller clone is a replica of an existing DC. Group of answer choices True False

A: Domain Controller:Domain controller is a server computer on Microsoft servers.The purpose of domain ...