我找不到丢失的":“在哪里。
我的代码是:
def A_star_Traversal(cost, heuristic, start_point, goals):
path = []
hashTable = {}
for i in goals:
hashTable[i] = 1
n = len(cost)
visited = [False for j in range (n)]
pq = [[0+heuristic[0],start_point]]
heapq.heapify(pq)
while(len(pq)):
v = heapq.heappop(pq)
if(hashTable.get(v)):
path.append(v)
break
visited[v] = True
path.append(v)
f=1
for i in range n: '''this is where i get the error'''
if(visited[i]==False and cost[v][i]>0):
pq.append([cost[v][i]+heuristic[i],i])
heapq.heapify(pq)
f=0
if(f):
path.pop()
return path我在for i in range n:上遇到了这个错误。
我查看了所有的for和while循环以及if else条件语句,确保每个语句都有':‘。然而,尽管没有发现遗漏的':',但编译清楚地表明我遗漏了它。我希望对其他人来说不会是一样的。
发布于 2021-09-05 07:27:37
在Python 3中(如果这是您正在使用的),它应该是:
for i in range(n):发布于 2021-09-05 07:27:55
试着这样做
for i in range(n):
#rest of the code我认为您得到了错误,因为您错过了括号()
发布于 2021-09-05 07:32:25
错误是因为您没有将n括在方括号中
for i in range(n):https://stackoverflow.com/questions/69061350
复制相似问题