C. Chess Boundary Positions: Write a program called chess_pos.pyOn a chessboard, positions are marked with letters between a and h for the column and a numberbetween 1 and 8 for the row. Give a 2 character input string with a letter (a-h) and a number (1-8), print"Corner" if the value indicates a square on a corner. Print "Border" if the value indicates a square on anedge of the board. Otherwise, print "Inside".

Question
Asked Sep 4, 2019
53 views

Please help me solve this problem 

C. Chess Boundary Positions: Write a program called chess_pos.py
On a chessboard, positions are marked with letters between a and h for the column and a number
between 1 and 8 for the row. Give a 2 character input string with a letter (a-h) and a number (1-8), print
"Corner" if the value indicates a square on a corner. Print "Border" if the value indicates a square on an
edge of the board. Otherwise, print "Inside".
help_outline

Image Transcriptionclose

C. Chess Boundary Positions: Write a program called chess_pos.py On a chessboard, positions are marked with letters between a and h for the column and a number between 1 and 8 for the row. Give a 2 character input string with a letter (a-h) and a number (1-8), print "Corner" if the value indicates a square on a corner. Print "Border" if the value indicates a square on an edge of the board. Otherwise, print "Inside".

fullscreen
check_circle

Expert Answer

Step 1

Program design:

Since the corner positions are a1,a8,h1,h8 in a chess board and the borders are any position which have a or h in the first letter of the position specification (string) and 1 or 8 in the second letter of the position specification we can build our logic for the program accordingly. So any position such as a2, a3…a7; h2,h3…h7, b1,c1…etc. would form the border. Although a1,a8,h1,h8 are also on the border as they are on the corner we would just call them as corner in our program.

 

In order to capture the above logic we would need one python list to hold the four corner positions and another to hold the first and second element of the position string for the border positions as follows:

corners = ['a1','h1','a8','h8']

borders = ['a','h','1','8']

 

we would use the following logic to determine if the position is a corner position or a border position as follows:

 

if position in corners:

        print("Corner")

elif position[0] in borders or position [1] in borders:

        print("Border")

Step 2

Program

We accept the position input from the user as follows:

 

position = input('Enter the board position (as a1, g2): ')

 

Hence the entire program could be defined as a function chess() as follows:

 

def chess():

    corners = ['a1','h1','a8','h8']

    borders = ['a','h','1','8']

   

    positio...

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

Python

Related Computer Science Q&A

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

Q: How do you convert 172.16.20.55 to binary format?

A: 172.16.20.55 represents IP address in decimal format. In order to convert it into binary format we n...

question_answer

Q: Fill in the following table to show how the given integers are represented, assuming that 16 bits ar...

A: Convert the integer value to binary:For positive integer:Divide the integer number by 2. The integer...

question_answer

Q: Design a payroll program that prompts user enter an employee's hourly pay rate and the number of hou...

A: Since nothing is mentioned about the programming language to be used, Java has been used as it is on...

question_answer

Q: use java Develop a program which allows the user to enter numbers into an array. Input will be as fo...

A: To develop this program  ,first of all you import  java.util.Scanner package in  which Scanner class...

question_answer

Q: Write a statement that outputs variable numObjects. End with a newline. Program will be tested with ...

A: As you have not specified the programming language, we are solving this question using Java programm...

question_answer

Q: Rainfall StatisticsWrite a program that lets the user enter the total rainfall for each of 12 months...

A: The following program is in C++ language and it is compiled in the “repl.it” compiler.Program plan:I...

question_answer

Q: Develop pseudocode for the problem of reading in an arbitrary number of DNA (deoxyribonucleic acid) ...

A: PseudocodeCreate a dictionary data structure to store the DNA base and the complementary base as ser...

question_answer

Q: Write two scnr.nextInt statements to get the input values into birthMonth and birthYear.Then write a...

A: Given below is the program to get input values for month and year and write the output value as a mo...

question_answer

Q: 1) Create a array of Fahrenheit temperatures, as follows int fahr []= {0,1,2,3,4,5,6,7,8,9,10,32,33,...

A: Program Instructions:Define the given array in code and calculate the size of the array.Use for loop...