निम्नलिखित प्रोग्राम का आउटपुट क्या है?
What is the output of the following program ?
def myfunc(a):
a=a+2
a=a*2
return a
print myfunc(2)
A
8
B
16
C
Indentation Error
D
Runtime Error
Explanation
Let's analyze the given Python code:
def myfunc(a):
a = a + 2
a = a * 2
return a
print(myfunc(2))
Step-by-Step Explanation:
-
Function Definition:
- The function
myfunc(a)takes one argumenta. - Inside the function:
- First,
a = a + 2increasesaby 2. - Then,
a = a * 2doubles the new value ofa.
- First,
- Finally, the function returns the value of
a.
- The function
-
Function Call:
- The function is called with
a = 2, so:a = 2 + 2→a = 4a = 4 * 2→a = 8
- The function then returns
8.
- The function is called with
-
Output:
- The
print(myfunc(2))will print the returned value, which is8.
- The
Answer:
(A) 8
-
प्रक्रिया: $a = 2 \rightarrow a = 2 + 2 = 4 \rightarrow a = 4 * 2 = 8$।
Correct Answer: A) 8