我想创建一个脚本,解决狼白菜山羊。每当我运行我的代码python崩溃。我的代码有什么问题导致它无法工作?我试图获得它,以便代码运行,然后打印解决问题的每一步。我的蟒蛇狼山羊白菜脚本崩溃python 2.6
search.py
class Nodes:
def succ(self, n):
raise Exception, "Successor undefined"
def start(self):
raise Exception, "Start undefined"
def goal(self, n):
raise Exception, "Goal undefined"
wolf_cabbage_goat.py
depth_first_search.py
def depth_first_search(problem, node):
if problem.goal(node): return [node]
# base case
for n_succ in problem.succ(node):
sol = depth_first_search(problem, n_succ)
if sol:
# first path is returned
return [node] + sol
wcg_run.py
import wolf_cabbage_goat
from depth_first_search import *
wcg = wolf_cabbage_goat.Wolf_Cabbage_Goat()
print depth_first_search(wcg, wcg.start())
请显示错误信息。 – laike9m 2014-10-29 10:27:14
@ laike9m没有错误代码弹出。这只是一个窗口,说“pythonw.exe已停止工作”,并给我关闭程序的选项 – 2014-10-29 10:30:42
它是否适用于其他版本的Python?你为什么使用2.6? – 2014-10-29 10:32:41