Warning: file_put_contents(/datas/wwwroot/jiajiahui/core/caches/caches_template/2/default/show.php): failed to open stream: Permission denied in /datas/wwwroot/jiajiahui/core/libraries/classes/template_cache.class.php on line 55

Warning: chmod(): Operation not permitted in /datas/wwwroot/jiajiahui/core/libraries/classes/template_cache.class.php on line 56
N次在另一个函数中运行一个函数 - 源码之家

N次在另一个函数中运行一个函数

N次在另一个函数中运行一个函数

问题描述:

我以前问过这种问题,但似乎我以前的问题有点误导,因为我的英语不好。我再次要求澄清。我真的很困惑。提前致谢。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 

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