在函数内运行另一个函数 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
相关问题:
1 个回答
2
在编程中,有时候我们需要处理一些数据,这些数据可能来自不同的地方,比如用户输入、文件或者网络请求。为了让程序能够理解这些数据,我们通常会把它们转换成一种特定的格式。
比如说,如果你有一个数字字符串“123”,你可能想把它变成一个真正的数字,以便进行数学运算。这个过程就叫做“类型转换”。
在不同的编程语言中,类型转换的方式可能会有所不同。有些语言会自动帮你转换,而有些则需要你手动去做。
总之,理解数据的类型和如何转换它们是编程中非常重要的一部分,这样才能让你的程序正常运行。
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