Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Accumulator-factory/Python/accumulator-factory-1.py
Normal file
26
Task/Accumulator-factory/Python/accumulator-factory-1.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
>>> def accumulator(sum):
|
||||
def f(n):
|
||||
f.sum += n
|
||||
return f.sum
|
||||
f.sum = sum
|
||||
return f
|
||||
|
||||
>>> x = accumulator(1)
|
||||
>>> x(5)
|
||||
6
|
||||
>>> x(2.3)
|
||||
8.3000000000000007
|
||||
>>> x = accumulator(1)
|
||||
>>> x(5)
|
||||
6
|
||||
>>> x(2.3)
|
||||
8.3000000000000007
|
||||
>>> x2 = accumulator(3)
|
||||
>>> x2(5)
|
||||
8
|
||||
>>> x2(3.3)
|
||||
11.300000000000001
|
||||
>>> x(0)
|
||||
8.3000000000000007
|
||||
>>> x2(0)
|
||||
11.300000000000001
|
||||
11
Task/Accumulator-factory/Python/accumulator-factory-2.py
Normal file
11
Task/Accumulator-factory/Python/accumulator-factory-2.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def accumulator(sum):
|
||||
def f(n):
|
||||
nonlocal sum
|
||||
sum += n
|
||||
return sum
|
||||
return f
|
||||
|
||||
x = accumulator(1)
|
||||
x(5)
|
||||
print(accumulator(3))
|
||||
print(x(2.3))
|
||||
9
Task/Accumulator-factory/Python/accumulator-factory-3.py
Normal file
9
Task/Accumulator-factory/Python/accumulator-factory-3.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
def accumulator(sum):
|
||||
while True:
|
||||
sum += yield sum
|
||||
|
||||
x = accumulator(1)
|
||||
x.send(None)
|
||||
x.send(5)
|
||||
print(accumulator(3))
|
||||
print(x.send(2.3))
|
||||
Loading…
Add table
Add a link
Reference in a new issue