Question: This is my Python code for a 2D word-search solver. I don't know why my matrix_search function keeps returning None, instead of the coordinates. This

This is my Python code for a 2D word-search solver. I don'tknow why my "matrix_search" function keeps returning None, instead of the coordinates.This is my test result and I'm trying to search for "aej"This is my Python code for a 2D word-search solver. I don't know why my "matrix_search" function keeps returning None, instead of the coordinates.

This is my test result and I'm trying to search for "aej" and the main function should print out the coordinates, but it's giving errors.

What is the problem and how can I fix it?

and the main function should print out the coordinates, but it's giving

10 11 import sys from typing import List from typing import Tuple 12 13 14 15 assert ( "linux" in sys.platform ), "This code should be run on Linux, just a reminder to follow instructions..." 16 17 18 19 20 21 22 23 24 def build_matrix(row, col) -> List[List[str]]: 1 = [] for i in range(row): 1.append([]) for j in range(col): 1[i].append("") return l 25 26 27 28 def matrix_search(matrix, word) -> Tuple[str, str]: 29 30 31 32 33 34 35 36 37 38 direction = [[1,0],[-1,0],[0,-1],[0,1],[-1,1],[1,-1],[-1,-1],[1,1]] for i in range(len(matrix)): for j in range(len(matrix[0])): if(matrix[i][j] == word[0]): start_i = i start_j = j k = 1 for a in direction: X = a[0] y = a[1] pos_X = i pos_y = j print("starting", i,j) pos_X += x pos_y += y check = True while k != len(word) and (check == True): 39 40 41 42 43 44 45 46 44 45 46 47 48 49 50 51 pos_y += y check = True while k != len(word) and (check == True): if(pos_x >= len(matrix)-1 or pos_x = len(matrix[@])-1 or pos_y None: matrix = [] Nmatrix = int(input()) data_input = input() list = input().split() row = int(list[@]) col = int(list[1]) for i in range(row): matrix.append(input().split()) word = input() empty = build_matrix(row,col) X, y = matrix_search(matrix, word) 79 80 = 71 72 row = def main() -> None: matrix [] Nmatrix = int(input()) data_input = input() list = input().split() int(list[@]) col = int(list[1]) for i in range(row): matrix.append(input().split()) word = input() empty = build_matrix(row, col) X, y = matrix_search(matrix, word) IL 82 print("Searching for " + (word) + + (word) + " in matrix + str(Nmatrix) + yields:") print("Search for start-position" + "(" + x[@] + x[1] + ")" + "end-position" 83 + "(" + y[0] + " ," + y[1] + ")") 84 85 86 if name '__main__": 87 main() 1 3 3 a b c def h i j aej starting oo letter i want e letter i have d I am here 1 0 starting oo starting 00 starting oo letter i want e letter i have b I am here 0 1 starting oo starting oo starting oo starting oo Traceback (most recent call last): File "word_up.py", line 87, in main() File "word_up.py", line 80, in main x, y = matrix_search(matrix, word) TypeError: cannot unpack non-iterable None Type object

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!