#239 · Functions · Beginner · 35 XP · about 5 min
Write make_counter(start=0, step=1) that returns a counter: a function that takes no arguments. The first call to the counter returns start, and every call after that returns step more than the call before.
Each counter keeps its own count, so two counters never affect each other.
c = make_counter() c() # returns 0 c() # returns 1 c() # returns 2 tens = make_counter(10, 5) tens() # returns 10 tens() # returns 15
First solves only, ranked by stars and then time.