Kodewick
Start learning →
Basic←→0 / 80

Click counter

#003BasicClasses5 min

The counter at the door goes up by one with each click. The class Clicker is half written: count starts at 0. Finish click(). tally(n) clicks n times and reads count.

Examples
tally(3)→3
tally(0)→0
main.py
class Clicker:
    def __init__(self):
        self.count = 0

    def click(self):
        # your code here: add 1 to this counter's own count
        pass


def tally(n):
    c = Clicker()
    for _ in range(n):
        c.click()
    return c.count
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.