Question: Write a Python function make _ repeater, which requires exactly two positional arguments, which are as follows. The first positional argument is a repeatable function,
Write a Python function makerepeater, which requires exactly two positional arguments, which are as follows.
The first positional argument is a repeatable function, which is one that can be called with only one positional argument, and whose result could safely be passed back into the same function as an argument.
The second positional argument is a repeat count, a nonnegative integer specifying how many times that function will be called.
The return value is a repeater function that itself requires one positional argument, an initial value, and calls the repeatable function the given number of times. The first time it's called, the initial value is passed to it; the second time it's called, the result of the first call is passed to it; the third time it's called, the result of the second call is passed to it; and so on The result of the last call is the result returned by the repeater function.
Additionally, there are two performance requirements that must be met by your makerepeater function.
Your makerepeater function must require O memory to run.
The repeater function returned by your makerepeater function must also require O additional memory to run ie independent of what the repeatable function does
Here's an example of how you'd expect the function to behave when you're done with it
def squaren: return n n quadruplesquare makerepeatersquare quadruplesquare # squaresquaresquaresquare singlesquare makerepeatersquare singlesquare # square donothing makerepeatersquare donothing # No calls to square, because the repeat count was
Limitations
The Python standard library is entirely offlimits in this problem. Your function must not require any module to be imported.
What to submit
Submit one Python script named problempy which contains your function and nothing else. Neither docstrings, comments, nor type annotations are required, since we've all agreed already on what problem we're solving here.
There is no credit being offered for writing automated tests though you certainly might want to since that's a great way to ensure that your code works as you expect and we'd prefer you not submit them even if you do
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
