class CounterReachMaxCountException(Exception): ... class MaxCounter: def __init__(self, max_count): self.max_count = max_count self.current_count = 0 def count_once(self, throw=True) -> bool: self.current_count += 1 if self.current_count >= self.max_count: if throw: raise CounterReachMaxCountException() else: return False return True def reset(self): self.current_count = 0 class Counter: def __init__(self, start=0): self.current_count = start def count_once(self, throw=True) -> bool: self.current_count += 1 return True def reset(self): self.current_count = 0