I'm trying to make a code that checks if there is a path in a maze from the first coordinate to the last represented by a matrix. I'm also trying to use queues. Here is the code I have so far:
from queue import Queue
maze=open(input())
matrix=maze.readlines()
matrix=[i.strip() for i in matrix]
matrix=[i.split() for i in matrix]
q=Queue()
row=0
column=0
q.put(row,column)
while not q.empty():
row,col=q.get()
if matrix[row][col+1]=="0" and col+1<len(matrix[0]):
q.put(row,col+1)
matrix[row][col+1]="2"
if matrix[row+1][col]=="0" and row+1<len(matrix):
q.put(row+1,col)
matrix[row+1][col]="3"
if matrix[row][col-1]=="0" and col-1>len(matrix[0]):
q.put(row,col-1)
matrix[x][x-1]="4"
if matrix[row-1][col]=="0" and row-1<len(matrix):
q.put(row-1,col)
matrix[row-1][col]="5"
What can I add to the end in order to get an output of "Yes" (if there is a path) and "No" if there isn't one?
Here is a sample of the text file containing a matrix.
0 0 0 0 1 0 0 0
0 1 1 0 1 0 1 0
0 1 0 0 1 0 1 0
0 0 0 1 0 0 1 0
0 1 0 1 0 1 1 0
0 0 1 1 0 1 0 0
1 0 0 0 0 1 1 0
0 0 1 1 1 1 0 0
I tried adding this at the end. I run my code and it says "'int' object is not iterable"
if matrix[7][7]=="2" "3" "4" or "5":
print "yes"
else:
print "no"