Pues bien tengo un problema con mi programa, al momento de compilarlo me marca error en una linea del main, especificamente en estas y no entiendo porque
Código Python:
Ver original
print ("______________________________________________________________________") print ('BFS Path') print (BFS(1,3,GRAPH))
Soy nueva en esto de la programación con Python y aunque he buscado información no logro comprendeer el error.
Les dejo el código:
Código Python:
Ver original
#import pygraphviz as pgv def BFS(start, target, GRAPH): 'Use a QUEUE to search.' print ("Source:",source) print("Target:",target) queue = [start] visited = [] while len(queue) > 0: x = queue.pop(0) if x == target: visited.append(x) return visited elif x not in visited: visited = visited+[x] if GRAPH[x] is not None: 'add nodes at the END of the queue' queue = queue + GRAPH[x] return visited def DFS(start, target, GRAPH): 'Use a STACK to search.' print ("Source:",source) print("Target:",target) stack = [start] visited = [] while len(stack) > 0: x = stack.pop(0) if x == target: visited.append(x) return visited elif x not in visited: visited = visited+[x] if GRAPH[x] is not None: 'add nodes at the top of the stack' stack = GRAPH[x] + stack return visited def main(): GRAPH = {1 : [2,3], 2:[4,5], 3:[6], 4:None, 5:[7,8], 6:None, 7:None, 8:None} print ("BFS Path",BFS(1,7,GRAPH)) print ("DFS Path",DFS(1,7,GRAPH) print ("______________________________________________________________________") print ('BFS Path') print (BFS(1,3,GRAPH)) print ("DFS Path",DFS(1,3,GRAPH))
Gracias!