Command Palette

Search for a command to run...

Hectal
Phase 5: Functions
Python · Exercise 5 of 6 PreviousNext
Intermediate

A counter that remembers

Write make_counter(start=0) that returns a function. Each call to that function adds 1 to a remembered count and returns the new count.

Two counters must be independent. The first call of a counter made with start=0 returns 1, and the first call of one made with start=10 returns 11.

What Check tests

  1. Counts 1, 2, 3
  2. Counters are independent
  3. Honours start
  4. Counters with different starts do not interfere
  5. A negative start works

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.