Q. Draw the entire environment, including all user-defined variables at the time line 10 is being executed.



def sum(a, b, c, d):                                              #1
    result = 0                                                          #2
    result = result + a + b + c + d                         #3
    return result                                                    #4
                                                                              #5
def length():                                                         #6
    return 4                                                            #7
                                                                              #8
def mean(a, b, c, d):                                            #9
    return float (sum (a, b, c, d))/length()          #10
                                                                             #11
print (sum(a, b, c, d), length(), mean(a, b, c, d))          #12



Answer =

When line 10 executes then it must be call from line 12.

At first line 12 is created in global environment. Then it call sum and create local environment within global environment. Then sum function return the values in global environment.

Then line 12 call length and create local environment within global environment. Then length function return the values in global environment. Then line 12 call mean and create local environment within global environment. Then mean function call sum and create nested local environment. Then sum function return values in local environment. Then mean function call length and create nested local environment. Then length function return values in local environment.

Then mean function return values in line 12 in global environment.

9 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. is this answer to be this big

    ReplyDelete
  2. This answer is too big ... Please post it again in short manner

    ReplyDelete
  3. There are some errors in this code so do we need to fix the errors and then write the code or do we have to ignore the errors and just write the entire environment

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post