tags:

views:

192

answers:

1

I have ask this kind of question before, but it seems my previous question is a bit misleading due to my poor English. I'm asking again to make clear. I am really confused about it. Thanks in advance.

Suppose I have a function A for generating the state of a cell in a certain rule, and I have another function which generates the state of a cell for N times, and each time the rule is as same as the fist function. And, yeah, don't know how to do it...

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  A: 
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
Martin
your answer is fantastic!!!it does work perfectly!thanks so much!!but i am not quite understand how does it work..would you explan it in words about that for loop,if you have time obviously.Thanks again
NONEenglisher
range(10) returns a list [0,1,2,3,4,5,6,7,8,9]
hasen j
That "else:" isn't necessary; just unindent the "return" statement.
Robert Rossney
`else` only make sense if you have a `break` statement in the loop.
J.F. Sebastian
Thanks for the comments, have amended accordingly.
Martin