Program - distinguish iter , iterables and iterator using example to print 10 random integers number


Topic: Program - distinguish iter , iterables and iterator using example to print 10 random integers number

Solution

class RandomInt:
    """
    This is the space to do documentation related to class.
    """
    def __init__(self):
       pass
    def __iter__(self):
        return self.RandomIntIterator(self)
    class RandomIntIterator:
        def __init__(self):
            self.count = 10
        def __iter__(self):
            return self
        def __next__(self):
            if self.count > 0:
                print(random.randint(0,10))
                self.count -= 1
            else:
                raise StopIteration



List all Python Programs