PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 109


Assuming that the following code has been executed successfully, which of the expressions evaluate to True? (Choose two.)

Show Answer
Correct Answer: BC

The function f(x, y) defines a nested function g() that returns the result of dividing x by y (nom by denom). When f(1, 2) is called, it returns the function g which will return 1/2 when invoked with a(). Similarly, f(3, 4) returns a different function g that will return 3/4 when invoked with b(). Therefore, a and b are different functions, making 'a != b' True. Also, since a is assigned to a function returned by f, 'a is not None' is True.

Discussion

3 comments
Sign in to comment
macxszOptions: BC
May 4, 2022

B. a != b C. a is not None

seaverickOptions: BC
Jan 27, 2024

def f(x,y): nom,denom = x,y def g(): return nom/denom return g a=f(1,2) b=f(3,4) print(a is not None) print(a!=b) print(a() == 4) print(b() == 4) B,C

Damon54Options: BC
Feb 8, 2024

Example Closure , def f(x, y): nom, denom = x, y def g(): return nom / denom return g a = f(1, 2) b = f(3, 4) fun1 = a fun2 = b print(fun1()) print(fun2())