Write a function in python show_board(board, queen=\'Q\', empty=\'-\'): Given a
ID: 3682021 • Letter: W
Question
Write a function in python show_board(board, queen='Q', empty='-'): Given a board, and the options indicate what character to use for cells with and without a queen, create a string that represents the indicated board. When we print the returned string, it should show the board on the screen, one line for each row and no spaces between cells. The last character should be a newline.
Assume: board is a list of lists of Booleans; queen and empty are single characters.
examples:
show_board([[True, False], [False, True]]) "Q- -Q "
show_board([[False, False, True, False], [False, True, False, False],[False, False, False, True], [False, False, False, False]])
"--Q- -Q-- ---Q ---- "
show_board([[False,False],[True,True]],'A','.') ".. AA " # changed characters
show_board([]) ""
Explanation / Answer
def show_board(board, queen='Q', empty='-'):
numrows = len(board)
for row in board:
for element in row:
if(element==True):
print queen,
else:
print empty,
print " "
print show_board([[True,False,False],[False,False,False],[True,False,False]])
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.