निम्नलिखित पायथन प्रोग्राम का आउटपुट ____ है
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
246
B
24
C
0
D
Error
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,xis4.
-
Apply
s(x):x = s(x)meansx = 4 * 3 = 12. Now,xis12.
-
Apply
r(x)again:x = r(x)meansx = 12 * 2 = 24. Now,xis24.
-
Final output:
print(x)prints the final value ofx, which is24.
Answer:
(B) 24
$x=2 \rightarrow r(2)=4 \rightarrow s(4)=12 \rightarrow r(12)=24$.
Correct Answer: B) 24