|
@@ -0,0 +1,96 @@
|
|
|
+
|
|
|
+
|
|
|
+def multiply(value):
|
|
|
+ def inner(x):
|
|
|
+ return value*x
|
|
|
+ return inner
|
|
|
+
|
|
|
+
|
|
|
+def make_repeater(n):
|
|
|
+ def inner(str):
|
|
|
+ return(str*n)
|
|
|
+ return inner
|
|
|
+
|
|
|
+'''
|
|
|
+def create_accumulator():
|
|
|
+ s = 0
|
|
|
+ def inner(x):
|
|
|
+ nonlocal s
|
|
|
+ s += x
|
|
|
+ return s
|
|
|
+ return inner
|
|
|
+'''
|
|
|
+
|
|
|
+
|
|
|
+def create_accumulator(start_value=0):
|
|
|
+ s = start_value
|
|
|
+ def inner(x):
|
|
|
+ nonlocal s
|
|
|
+ s += x
|
|
|
+ return s
|
|
|
+ return inner
|
|
|
+
|
|
|
+
|
|
|
+def countdown(x):
|
|
|
+ counter = start = x
|
|
|
+ def inner():
|
|
|
+ nonlocal counter
|
|
|
+ if counter <= 0:
|
|
|
+ print(f"Превышен лимит, вы вызвали более {start} раз")
|
|
|
+ else:
|
|
|
+ print(counter)
|
|
|
+ counter -= 1
|
|
|
+ return inner
|
|
|
+
|
|
|
+
|
|
|
+def count_calls():
|
|
|
+ counter = 0
|
|
|
+ def inner():
|
|
|
+ inner.total_calls += 1
|
|
|
+ return inner.total_calls
|
|
|
+ setattr(inner, 'total_calls', 0)
|
|
|
+ return inner
|
|
|
+
|
|
|
+
|
|
|
+def my_func(a):
|
|
|
+ def inner(x):
|
|
|
+ return x - a
|
|
|
+ return inner
|
|
|
+
|
|
|
+
|
|
|
+def main():
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ counter = count_calls()
|
|
|
+ counter()
|
|
|
+ counter()
|
|
|
+ print(counter.total_calls)
|
|
|
+ counter()
|
|
|
+ print(counter.total_calls)
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ main()
|