Define a class with a generator that can iterate the numbers, which are divisible by 7, between a given range of 0 and n

Question:

Define a class with a generator that can iterate the numbers, which are divisible by 7, between a given range of 0 and n.

Hints:

Consider use yield

Solution:

def putNumbers(n):
    i = 0
    while i<n:
        j=i
        i=i+1
        if j%7==0:
            yield j

for i in reverse(100):
    print i
Code language: Python (python)

Leave a Comment