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.
7
6
5
4
3
2
1
ab cde f g h
help_outline

Image Transcriptionclose

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

fullscreen
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

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.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

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

Q: EXPLAIN ALL STEPS: Determine the output of the following Pep/9 machine language program if the input...

A: Address   Instruction(in hex)0000         D1FC15Convert the instructions into binary form-D=11011=00...

question_answer

Q: Write a program in Python that converts an improper fraction to a mixed number. The program should p...

A: Program:#Display the messageprint("Calculate Mixed Number")print("======================")print()#Pr...

question_answer

Q: JAVA threads confused help 1. A)Consider the Java program. What is the expected logical output? What...

A: Multithreading in java: It is an essential feature of java that performs two or more programs to run...

question_answer

Q: Vectors Write a for loop to print all NUM_VALS elements of vector courseGrades, following each with ...

A:  Note: As the user given index value is constant and so the value of index could not be changed whil...

question_answer

Q: Problem 3 Guessing game: For this program, have the user guess a number from 1-5. Next, generate a r...

A: Program instructions:Create a form with two fields and one submit button.User enters the number in a...

question_answer

Q: Write a program that displays the income tax due on taxable income entered by the user. Have the use...

A: The program that displays the income tax due on taxable income is created in java.In calTax() method...

question_answer

Q: Simplify the following Boolean function , using three- variable maps: d) F(x,y,z) = Σ (3,5,6,7)

A: The Boolean function is defined by the algebraic expression known as Boolean expression which contai...

question_answer

Q: I need help with Excel in my Intro to info systems. The thing i don't know how to do is this: It kee...

A: To solve this question user must know the definition of absolute reference:Absolute reference: An ab...

question_answer

Q: Analyze the code snippet below: package package1;import java.io.BufferedReader;import java.io.IOExce...

A: There is only one class involved in this code.The class name is: WebPageTextReader.Explanation:After...