Computer Science
Draw flow of execution for the above program.
Python Functions
3 Likes
Answer
The flow of execution for the above program is as follows :
1 → 6 → 9 → 12 → 1 → 2 → 3 → 4 → 6 → 7 → 9 → 10 → 12
Line 1 is executed and determined that it is a function header, so entire function-body (i.e, lines 2, 3, 4) is ignored.Then line 6 is executed and determined that it is a function header, so entire function-body (i.e, line 7) is ignored, Line 9 is executed and determined that it is a function header, so entire function-body (i.e, line 10) is ignored. Then line 12 is executed and it has a function calls, so control jumps to the function header (line 1) and then first line of function-body, i.e, line 2, function returns after line 4 to function call line (line 12) and then control jumps to line 6, it is a function header and then first line of function-body, i.e., line 7, function returns after line 7 to function call line (line 12) and then control jumps to line 9, it is a function header and then first line of function-body, i.e., line 10, function returns after line 10 to function call line 12.
Answered By
2 Likes
Related Questions
Find the errors in code given below :
def alpha (n, string = 'xyz', k = 10) : return beta(string) return n def beta (string) return string == str(n) print(alpha("Valentine's Day"):) print(beta(string = 'true')) print(alpha(n = 5, "Good-bye"):)
Draw the entire environment, including all user-defined variables at the time line 10 is being executed.
1. def sum(a, b, c, d): 2. result = 0 3. result = result + a + b + c + d 4. return result 5. 6. def length(): 7. return 4 8. 9. def mean(a, b, c, d): 10. return float(sum(a, b, c, d))/length() 11. 12. print(sum(a, b, c, d), length(), mean(a, b, c, d))
Find and write the output of the following python code :
a = 10 def call(): global a a = 15 b = 20 print(a) call()
In the following code, which variables are in the same scope ?
def func1(): a = 1 b = 2 def func2(): c = 3 d = 4 e = 5