我的操作系統不支持Sage 5.4,因此我現在只能使用5.0。 定義這個函數在Python中沒有註冊語法錯誤,我不認爲它在Sage 5.4中犯了錯誤(如果可能,我會很感激的。)我想知道它爲什麼在5.0中失敗。sage 5.0令人困惑的語法錯誤
def num_matchings(G):
if min(G.degree_sequence())== 0 or G.num_edges()==0:
return 0
elif G.num_edges()==1:
if G.edges()[0][2] ==None:
return 1
else:
return G.edges()[0][2]
else:
H = copy(G)
K = copy(G)
e = G.edges()[0]
if e[2] ==None:
w=1
else:
w = e[2]
H.delete_edge(e)
K.delete_vertices([e[0],e[1]])
return num_matchings(H) + w*num_matchings(K)
的第一個錯誤,我得到當我嘗試定義是
File "<ipython console>", line 4 ==Integer(1): ^ SyntaxError: invalid syntax
,他們堆在後。在我看來,語法看起來很好。
我在Mac OS 10.5上使用GCC 4.0.1。
任何幫助非常感謝。
完美。非常感謝! – WKA
+1 - 從來不知道'%cpaste'(甚至'%paste' :)) – RocketDonkey