Reading Time: 1 minutes
Generator of Multiples of 7 in Python
Generator of Multiples of 7: Write a generator function which yields multiples of 7 lying between 0 and a given number.
Generator of Multiples of 7
def generatorOfMultiplesOf7(upperBound): for number in range(1, upperBound + 1): if number % 7 == 0: yield number upperBound = input("Please enter the number up until which you want multiples of 7: ") generatorObject = generatorOfMultiplesOf7(int(upperBound)) print(next(generatorObject)) # 7 print(next(generatorObject)) # 14 print(next(generatorObject)) # 21