Question: in python please Write a function that, when given a list of rooks on a chessboard and a square on the chessboard, returns the number

in python please Write a function that, when given a list ofin python please

Write a function that, when given a list of rooks on a chessboard and a square on the chessboard, returns the number of times the square is attacked by the rooks, The chessboard is an 8 by 8 grid, with each square a tuple of a column ('a' through 'h') and a row (1 through 8). A rook moves vertically and horizontally, attacking each square on its column or its row (but not both - it can't defend itself). We assume the rooks can pass through each other - a rook on a8 can attack the square a3 even if there is another rook on a5. The below image highlights all the squares that a particular rook attacks. So using the above image as an example value, if rooks is [('e',4)) and square is ('e',3), the function should return 1 because the square at location is attacked by the one rook. But if rooks is [('e',4)) and square is (1,8), the function should return 0. In other words, numattackingrooks([('e',4), ('e',3)) = 1 numattackingrooks([['e',4)), ('f',8)) = 0 Hint: You'll want to keep a counter variable during the loop that keeps track of the number of attacking rooks. For each rook, you want to increment the counter (this means increase it by 1) if that rook attacks the square in question. Write a function that, when given a list of rooks on a chessboard and a square on the chessboard, returns the number of times the square is attacked by the rooks, The chessboard is an 8 by 8 grid, with each square a tuple of a column ('a' through 'h') and a row (1 through 8). A rook moves vertically and horizontally, attacking each square on its column or its row (but not both - it can't defend itself). We assume the rooks can pass through each other - a rook on a8 can attack the square a3 even if there is another rook on a5. The below image highlights all the squares that a particular rook attacks. So using the above image as an example value, if rooks is [('e',4)) and square is ('e',3), the function should return 1 because the square at location is attacked by the one rook. But if rooks is [('e',4)) and square is (1,8), the function should return 0. In other words, numattackingrooks([('e',4), ('e',3)) = 1 numattackingrooks([['e',4)), ('f',8)) = 0 Hint: You'll want to keep a counter variable during the loop that keeps track of the number of attacking rooks. For each rook, you want to increment the counter (this means increase it by 1) if that rook attacks the square in

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!