Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Counter:
"""
Simple counter with increment, decrement, and value retrieval.
"""
def __init__(self, initial: int = 0):
self._value = int(initial)

def increment(self, amount: int = 1) -> int:
"""Increase the counter by 'amount' (default 1) and return new value."""
self._value += int(amount)
return self._value

def decrement(self, amount: int = 1) -> int:
"""Decrease the counter by 'amount' (default 1) and return new value."""
self._value -= int(amount)
return self._value

def get_value(self) -> int:
"""Return the current value of the counter."""
return self._value