निम्नलिखित पायथन प्रोग्राम का आउटपुट ____ है
The output of following Python program is _____.
r = lambda q: q*2
s = lambda q: q * 3
x = 2
x = r(x)
x = s(x)
x = r(x)
print x
A)
B)
C)
D)
Explanation:
Let's break down the given Python code step by step:
r = lambda q: q * 2
s = lambda q: q * 3
x = 2
x = r(x)
x = s(x)
x = r(x)
print(x)
Step-by-Step Explanation:
-
Define the lambdas:
r = lambda q: q * 2
: This lambda function doubles the input.s = lambda q: q * 3
: This lambda function triples the input.
-
Initial value of
x
:x = 2
-
Apply
r(x)
:x = r(x)
meansx = 2 * 2 = 4
. Now,x
is4
.
-
Apply
s(x)
:x = s(x)
meansx = 4 * 3 = 12
. Now,x
is12
.
-
Apply
r(x)
again:x = r(x)
meansx = 12 * 2 = 24
. Now,x
is24
.
-
Final output:
print(x)
prints the final value ofx
, which is24
.
Answer:
(B) 24