Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
479 B
2
Indexable
Never
class CustomerCounter:
    def __init__(self, max=5):
        self.max = max
    def __iter__(self):
        self.count = 0
        return self

    def __next__(self):
        self.count += 1

        if self.count > self.max:
            raise StopIteration
        return self.count


customer_counter = CustomerCounter()
i = iter(customer_counter)
print(next(i))
print(next(i))
print(next(i))
print(next(i))


for customer_count in customer_counter:
    print(customer_count)