[Type B] Working with Functions – Chapter 3 Sumita Arora

|
Table of Contents

3. Consider the following code and write the flow of execution for this. Line numbers have been given for your reference.

Python
def power(b, p):
    y = b ** p
    return y

def calcSquare(x):
    a = power(x, 2)
    return a

n = 5
result = calcSquare(n)
print(result)

Solution:

  1. power function is defined.
  2. calcSquare function is defined.
  3. n is assigned the value 5.
  4. calcSquare function is called with argument n.
  5. Inside calcSquare, power function is called with arguments x and 2.
  6. power function calculates the square of x.
  7. The result is returned and assigned to result.
  8. result is printed.

In short, flow of execution is as follows:

  1. Define power function.
  2. Define calcSquare function.
  3. Assign n = 5.
  4. Calculate square of n using calcSquare.
  5. Print the result.
"Spread the light within, illuminate the hearts around you. Sharing is not just an action, but a sacred journey of connecting souls."~ Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *