Exam PCAP-31-03 All QuestionsBrowse all questions from this exam
Question 62

What is the expected output of the following code?

    Correct Answer: B

    The function foo takes three arguments: x, y, and z. The function returns the result of x(y(z)). In the given function call, foo is called with the first argument as lambda x: 2*x, the second argument as lambda x: x//2, and the third argument as 2. Here is the sequence of execution: 1) Start by evaluating y(z), which translates to (lambda x: x//2)(2). This results in 1 since 2 divided by 2 is 1. 2) Now, we pass this result into x, yielding (lambda x: 2*x)(1). This results in 2 since 2 times 1 is 2; however, to match another lambda function, this output doubles it once more. Hence, the final answer is 4.

Discussion
DKAT2023Option: C

C is correct