fork download
  1. def counter(start):
  2. x = [start]
  3.  
  4. def adder(y):
  5. """Increment the counter and return the new value."""
  6. x[0] += 1
  7. return x[0] + y
  8.  
  9. return adder
  10.  
  11. adder = counter(start=0)
  12. print(adder(5))
  13. print(adder(5))
  14. print(adder(5))
  15.  
Success #stdin #stdout 0.04s 64072KB
stdin
Standard input is empty
stdout
6
7
8