Your task
Define Counter with value initially 0 and increment() adding 1. Increment twice and print value.
Expected output
2
Worked solution
class Counter:
def __init__(self):
self.value = 0
def increment(self):
self.value += 1
c = Counter()
c.increment()
c.increment()
print(c.value)Checks compare printed output, not your approach. Several solutions can be valid.
← Back to courses