I'm trying to write a function that takes a function as its argument and returns a new function that runs said function a given number of times.
For example, if I had a function:
return num * 2
doubleThrice = repeatFunction(doubleNumber, 3)
doubleThrice(3) # Returns 18 but should it?
def repeatFunction(func, n):
return func(inp) * n
If you want to apply a function several times, you probably need a loop that repeats that many times:
def repeatFunction(func, n): def inner(inp): for i in range(n): inp = func(inp) return inp return inner