Skip to content

Question 30

Create a function named make_function(n) which will return another function that checks if a number is divisible by n.

Sample output:

>>> f3 = make_function(3)
>>> print(f3(6))
True
>>> print(f3(31))
False
>>> f7 = make_function(7)
>>> print(f7(17))
False
>>> print(f7(63))
True

Complete the code below by filling in the blank. [5 marks]

def make_function(n):
    return ____BLANK_1____
Model Solution
def make_function(n):
    return lambda x:x%n==0
  • Blank 1: lambda x: x % n == 0