【问题标题】:Project IA in Python -- UnboundLocalError: local variable 'x' referenced before assignmentPython 中的项目 IA -- UnboundLocalError: 分配前引用的局部变量“x”
【发布时间】:2016-09-08 20:14:33
【问题描述】:

`

def iterativeDeepeningSearch(problem):
    def depthLimitedDFS(node, problem, depth):
        if depth==0:
            return
        if problem.isGoalState(node[-1]):
            return node
        for move, acao, c in problem.getSuccessors(node[-1]):
            if move not in node: 
                ode = depthLimitedDFS(node+[move],problem, depth-1)
        if x:
            return x

    for depth in itertools.count():
        node = depthLimitedDFS([problem.getStartState()], problem, depth)
        if node:
            return node`

我正在尝试将此代码执行到项目(Pacman)中,但它返回错误:Un bound Local Error: local variable 'x' referenced before assignment....

【问题讨论】:

  • 您有一行if x:,但从未定义变量x...
  • 我忘记在'x'中转入变量'ode'

标签: python python-2.7 search graph


【解决方案1】:

python 对您说的是,您尝试在对其进行任何分配之前使用x。也就是说:您没有使用x 根本,并且您正在尝试检查它的可能值(这没有意义)。

x 在您的代码中应该做什么?考虑一下,您可能会想出解决问题的方法。

【讨论】:

  • 我忘记在'x'中转入变量'ode'
猜你喜欢
  • 2015-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-10
  • 2020-01-16
相关资源
最近更新 更多