Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function in python called is_square(board): Given a board as a list of l

ID: 3681593 • Letter: W

Question

Write a function in python called is_square(board): Given a board as a list of lists of Booleans, check whether it represents a square board with the same number of rows and columns. If the rows don't all have the same number of items in them, or if the number of rows does not match the number of columns, this function returns False. Empty board is square.

o Assume: board is a list of lists of Booleans.

Examples:

is_square([[True,False,False],[False,False,False],[True,False,False]]) True

is_square([[True,False,False],[False,False,False]]) False #2 rows x 3 columns

is_square([[True],[False,False],[True,False,False]]) False #rows not same length

Explanation / Answer

def is_square(board):
if board is None:
return True
else:
numrows = len(board)
for element in board:
numcols = len(board[0])
if(numcols!=numrows):
return False
return True

print is_square([[True,False,False],[False,False,False],[True,False,False]])

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote