Answer to Question #332074 in Python for kkkkkjjjjjjjjjjjjj

Question #332074

Ash is now an expert in python function topic. So, he decides to teach others what he knows by making a question on it. Problem statement of his question is as follows.

Your task is to write a function outer_layer(num) that returns function inner_layer, where num is a positive integer. Function inner_layer(div) check whether num is divisible by div or not, its return type is bool (True/ False).

num is of type string

div is of type int and belongs to {2, 5, 9, 10}


Functions are Objects - Since functions are just like variables, they can be returned from a function!

def outer_layer():
  print 'This is outer layer'
  def inner_layer():
    print 'This is inner layer'
  return inner_layer

def __name__ == '__main__':
func_obj = outer_layer() # func_obj now becomes inner_layer, and This is outer layer is printed on the screen.
func_obj()

Output:

This is outer layer
This is inner layer






1
Expert's answer
2022-04-21T14:37:00-0400
def outer_layer(num):
  def inner_layer(div):
    for i in range(len(div)):
      if (num % div[i]) != 0:
        return False
    return True
  return inner_layer

if __name__ == '__main__':
  num = int(input("Input num: "))
  print("Output:")
  func_obj = outer_layer(num)
  print(func_obj([2, 5, 9, 10]))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS