Language is Python 3.5.2 Why am I getting the error "if board[0][j] != board[i][j]: builtins.IndexError: list index out of range" for the code below? import random def start(board): length =...

Language is Python 3.5.2 Why am I getting the error "if board[0][j] != board[i][j]: builtins.IndexError: list index out of range" for the code below? import random def start(board): length = eval(input("Enter the length of a square matrix: ")) global length for i in range(length): board.append([]) for j in range(length): board[i].append(random.randint(0, 1)) print(board[i][j], end = "") print() return def checkcolumns(board): # Check columns for j in range(length): same = True for i in range(1, length): if board[0][j] != board[i][j]: same = False return if same: print("All " + str(board[0][j]) + "'s on column " + str(j)) isSameOnAColumn = True return def checkRows(board): # Check rows for i in range(length): same = True for j in range(1, length): if board[i][0] != board[i][j]: same = False return if same: print("All " + str(board[i][0]) + "'s on row " + i) isSameOnARow = True return def majorDiagonal(board): # Check major diagonal same = True for i in range(1, length): if board[0][0] != board[i][i]: same = False return if same: print("All " + str(board[0][0]) + "'s on major diagonal") isSameOnADiagonal = True return def conditions(board): if not isSameOnARow: print("No same numbers on a row") if not isSameOnAColumn: print("No same numbers on a column") if not isSameOnADiagonal: print("No same numbers on the major diagonal") if not isSameOnASubdiagonal: print("No same numbers on the sub-diagonal") return def main(): board = [] isSameOnARow = False isSameOnAColumn = False isSameOnADiagonal = False start(board) checkcolumns(board) checkRows(board) majorDiagonal(board) conditions(board)
May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here