It is possible to place 8 queens on an 8×8 chessboard so that notwo queens threaten each other. Thus, it requires that no twoqueens share the same row, column, or diagonal.
Write a Python program that, given a placement of 8 queens onthe chessboard , prints YES if there is a pair of queens thatviolates this rule and otherwise prints NO. The input consistsof eight coordinate pairs, one pair per line, with each pair givingthe position of a queen on a standard chessboard with rows andcolumns numbered from 1 to 8.
Use the following code as a base:
def check_queens_chessboard(x, y):(INSERT YOUR CODE HERE)x = []y = []inputs in range(8): a_list = [int(s) for s in input().split()] # Use listcomprehension to get input data x.append(a_list[0]) y.append(a_list[1])print(check_queens_chessboard(x, y))Example input:1 5
2 3
3 1
4 7
5 2
6 8
7 6
8 4
Example output: NO
It is possible to place 8 queens on an 8×8 chessboard so that no two queens threaten each other. Thus, it requires that
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am