← Python from Scratch Lesson 63 of 78 · 5 XP

Warm-up: a counter warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

Methods can change an object's data through self:

class Counter:
    def __init__(self):
        self.value = 0

    def add(self):
        self.value = self.value + 1

c = Counter()
c.add()
c.add()
print(c.value)   # 2

Task. Finish the add() method of the Counter class: each call increases value by 1.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.