我想創建一個腳本,解決狼白菜山羊。每當我運行我的代碼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