Closures
Completed
Write make_counter(step) that returns a function; each call of that function returns the next value step, 2*step, 3*step, …. Read step and n and print n calls on one line.
Input
One line: step n.
Output
One line.
Example
Input
5 4
Output
5 10 15 20
Editor
Python
Hints
An inner function can remember variables from the enclosing function.
Use nonlocal to update them.
Solution explanation
The inner function keeps value alive after make_counter returns — a closure.
Show solution
def make_counter(step):
value = 0
def counter():
nonlocal value
value += step
return value
return counter
step, n = map(int, input().split())
next_value = make_counter(step)
print(*[next_value() for _ in range(n)])