Q:

Create an inner function to calculate the addition in the following way using python programming

belongs to collection: Python Functions Exercises

0

Create an inner function to calculate the addition in the following way

  • Create an outer function that will accept two parameters, a and b
  • Create an inner function inside an outer function that will calculate the addition of a and b
  • At last, an outer function will add 5 into addition and return it

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

In Python, we can create a nested function inside a function. We can use the nested function to perform complex tasks multiple times within another function or avoid loop and code duplication.

# outer function
def outer_fun(a, b):
    square = a ** 2

    # inner function
    def addition(a, b):
        return a + b

    # call inner function from outer function
    add = addition(a, b)
    # add 5 to the result
    return add + 5

result = outer_fun(5, 10)
print(result)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a python program to create a recursive funct... >>
<< Create a function with default argument using pyth...