{ Generators, Iterators and Decorators Exercises. }

Implement the following functions:


This function should accept a number and return the next number that is divisible by it.

gen_multiple_of_two = get_next_multiple(2)
next(gen_multiple_of_two) # 2
next(gen_multiple_of_two) # 4
next(gen_multiple_of_two) # 6
next(gen_multiple_of_two) # 8

gen_multiple_of_thirteen = get_next_multiple(13)

next(gen_multiple_of_thirteen) # 13
next(gen_multiple_of_thirteen) # 26
next(gen_multiple_of_thirteen) # 39
next(gen_multiple_of_thirteen) # 52


This function should accept a number and return True or False if the number is a prime number.

is_prime(11) # True
is_prime(122) # False


This function should return a generator that yields in the next prime number. The highest it should go should be 1000.

gen = get_next_prime()



This decorator function should return the result of another function multiplied by two

def add(a,b):
    return a+b

add(5,5) # 10

def add(a,b):
    return a+b

add(5,5) # 20


This decorator function should only allow a function to have even parameters or else return the string "Please only use even numbers!"

def add(a,b):
    return a+b

add(5,5) # "Please add even numbers!"
add(4,4) # 8

def multiply(a,b,c,d,e):
    return a*b*c*d*e


This function should accept a list or tuple and return the sum of each index. As a bonus, make this function able to accept a variable number of arguments.

sum_index([1,2,3,4]) # 6


Research the built in zip method, what does it do? Start here

For solutions to these exercises, click here.

When you're ready, move on to Web Scraping