Foros del Web » Programando para Internet » Python »

[SOLUCIONADO] Invalid syntax error - Python

Estas en el tema de Invalid syntax error - Python en el foro de Python en Foros del Web. Hola Pues bien tengo un problema con mi programa, al momento de compilarlo me marca error en una linea del main, especificamente en estas y ...
  #1 (permalink)  
Antiguo 19/05/2013, 09:12
Avatar de BerhtSammet  
Fecha de Ingreso: mayo-2013
Ubicación: México
Mensajes: 1
Antigüedad: 10 años, 11 meses
Puntos: 0
Exclamación Invalid syntax error - Python

Hola
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
  1. print ("______________________________________________________________________")
  2.     print ('BFS Path')
  3.     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
  1. #import pygraphviz as pgv
  2.  
  3.  
  4. def BFS(start, target, GRAPH):
  5.     'Use a QUEUE to search.'
  6.     print ("Source:",source)
  7.     print("Target:",target)
  8.     queue = [start]
  9.     visited = []
  10.  
  11.     while len(queue) > 0:
  12.       x = queue.pop(0)
  13.  
  14.       if x == target:
  15.         visited.append(x)
  16.         return visited
  17.       elif x not in visited:
  18.         visited = visited+[x]
  19.         if GRAPH[x] is not None:
  20.            'add nodes at the END of the queue'
  21.            queue = queue + GRAPH[x]
  22.  
  23.     return visited
  24.  
  25. def DFS(start, target, GRAPH):
  26.     'Use a STACK to search.'
  27.     print ("Source:",source)
  28.     print("Target:",target)
  29.     stack = [start]
  30.     visited = []
  31.  
  32.     while len(stack) > 0:
  33.       x = stack.pop(0)
  34.  
  35.       if x == target:
  36.         visited.append(x)
  37.         return visited
  38.       elif x not in visited:
  39.         visited = visited+[x]
  40.         if GRAPH[x] is not None:
  41.            'add nodes at the top of the stack'
  42.            stack = GRAPH[x] + stack
  43.  
  44.     return visited
  45.  
  46.  
  47. def main():
  48.  
  49.     GRAPH = {1 : [2,3], 2:[4,5], 3:[6], 4:None, 5:[7,8], 6:None, 7:None, 8:None}
  50.  
  51.  
  52.     print ("BFS Path",BFS(1,7,GRAPH))
  53.     print ("DFS Path",DFS(1,7,GRAPH)
  54.     print ("______________________________________________________________________")
  55.     print ('BFS Path')
  56.     print (BFS(1,3,GRAPH))
  57.     print ("DFS Path",DFS(1,3,GRAPH))

Gracias!

Última edición por BerhtSammet; 19/05/2013 a las 09:50
  #2 (permalink)  
Antiguo 19/05/2013, 18:21
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Invalid syntax error - Python

En la linea 53 de tu código.

Código Python:
Ver original
  1. print ("DFS Path",DFS(1,7,GRAPH)

Te falto cerrar un paréntesis.

Puedes pasar al foro de python para futuras preguntas.

http://www.forosdelweb.com/f130/

Etiquetas: print, programación-general
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:50.