apply_n_times(func, value, n) that applies the single-argument function func to value, repeated n times, feeding each result back in as the next input, and returns the final result. apply_n_times itself must not be a one-liner recursion; use an ordinary loop.def double(x): return x * 2 apply_n_times(double, 3, 4)
48
3 -> 6 -> 12 -> 24 -> 48 after 4 applications of double.
apply_n_times(double, 5, 0)
5
Zero applications returns the original value unchanged.
Use a for loop that runs n times, reassigning value = func(value) each iteration.
If n is 0, the loop body never runs and value is returned unchanged.