NONEenglisher
NONEenglisher

Reputation: 1835

run a function in another function in N times

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

Upvotes: 0

Views: 682

Answers (1)

Martin
Martin

Reputation: 40365

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

Upvotes: 2

Related Questions