PCAP-31-03 Exam QuestionsBrowse all questions from this exam

PCAP-31-03 Exam - Question 36


What is the expected output of the following code?

Show Answer
Correct Answer: D

The code defines a function foo that takes three arguments: x, y, and z. The function returns the result of the lambda function x applied to y minus the lambda function x applied to z. In the print statement, the lambda function x is defined as lambda x: x % 2, which returns the remainder when x is divided by 2. When the lambda function is applied to 2, the result is 2 % 2, which is 0. When the lambda function is applied to 1, the result is 1 % 2, which is 1. Therefore, the result of foo(lambda x: x % 2, 2, 1) is 0 - 1, which equals -1.

Discussion

3 comments
Sign in to comment
Dave304409Option: D
Jul 3, 2024

Correct

a4129fdOption: D
May 30, 2024

As tested in my IDE

DKAT2023Option: D
Jul 1, 2024

D is correct