2008-12-13 194 views
0

我以前問過這種問題,但似乎我以前的問題有點誤導,因爲我的英語不好。我再次要求澄清。我真的很困惑。提前致謝。N次在另一個函數中運行一個函數

假設我有一個函數A用於生成一定規則中的單元格的狀態,並且我有另一個函數生成單元格的狀態N次,並且每次規則與第一個函數相同。而且,是啊,不知道該怎麼做...

def 1st_funtion(a_matrixA) 
    #apply some rule on a_matrixA and return a new matrix(next state of the cell) 
    return new_matrix 

def 2nd_funtion(a_matrixB,repeat_times=n) 
    #how to import the 1st_funtion and run for n times and return the final_matrix? 
    #I know if n=1, just make final_matrix=1st_funtion(a_matrixB) 
    return final_matrix 

回答

2
def 1st_funtion(a_matrixA) 
    #apply some rule on a_matrixA and return a new matrix(next state of the cell) 
    return new_matrix 

def 2nd_funtion(a_matrixB,repeat_times) 

    for i in range(repeat_times): 
     a_matrixB = 1st_funtion(a_matrixB) 
    return a_matrixB 
+0

你的答案是太棒了!它很好地工作!非常感謝! 但我不是很明白它是如何工作的。如果你有明確的時間,你可以用關於循環的文字來解釋它。再次感謝 – NONEenglisher 2008-12-13 16:48:39