# 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
53 views

check_circle

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

#### 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