Generate random number using the concept of iterators


Topic: Generate random number using the concept of iterators

Solution

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



List all Python Programs