Filter by year

Programming in Python questions

Q16

GATE DA 2026 DAProgramming in PythonMCQ1 mark−1/3 if wrong

Report a problem with Q16

What is wrong?
Consider the given Python program.
def append_to_lst(val, lst=[]):
    lst.append(val)
    return lst
print(append_to_lst(1))
print(append_to_lst(2))
print(append_to_lst(3, []))
Which of the following is the correct output of this program?
Show answer without attempting

Loading the answer…

Q50

GATE DA 2026 DAProgramming in PythonMSQ2 marks

Report a problem with Q50

What is wrong?
Consider the given Python program.
def outer():
    x = []
    def inner(val):
        x.append(val)
        return x
    return inner
f1 = outer()
f2 = outer()
print(f1(10)) # Line P
print(f1(20)) # Line Q
print(f2(30)) # Line R
print(f1(40)) # Line S
Which of the following options is/are correct?
More than one option can be correct.
Show answer without attempting

Loading the answer…

Q58

GATE DA 2026 DAProgramming in PythonNAT2 marks

Report a problem with Q58

What is wrong?
Consider the given Python program.
def fun(L, i=0):
    if i >= len(L)-1:
        return 0
    if L[i] > L[i+1]:
        L[i+1], L[i] = L[i], L[i+1]
        return 1+fun(L, i+1)
    else:
        return fun(L, i+1)

data = [5, 3, 4, 1, 2]
count = 0
for _ in range(len(data)):
    count += fun(data)
print(count)
The output of the program is __________ . (Answer in integer)
Show answer without attempting

Loading the answer…

Q23

GATE DA 2025 DAProgramming in PythonMCQ1 mark−1/3 if wrong

Report a problem with Q23

What is wrong?
Consider the following Python declarations of two lists.
A=[1,2,3]
B=[4,5,6]
Which one of the following statements results in A= [1, 2, 3, 4, 5, 6]?
Show answer without attempting

Loading the answer…

Q47

GATE DA 2025 DAProgramming in PythonMCQ2 marks−2/3 if wrong

Report a problem with Q47

What is wrong?
Consider the following Python code snippet.
A={"this","that"}
B={"that","other"}
C={"other","this"}
while "other" in C:
    if "this" in A:
        A,B,C=A-B,B-C,C-A
    if "that" in B:
        A,B,C=C|A,A|B,B|C
When the above program is executed, at the end, which of the following sets contains "this"?
Show answer without attempting

Loading the answer…

Q63

GATE DA 2025 DAProgramming in PythonNAT2 marks

Report a problem with Q63

What is wrong?
Consider the following Python code snippet.
def f(a,b):
    if (a==0):
        return b
    if (a%2==1):
        return 2*f((a-1)/2,b)
    return b+f(a-1,b)

print(f(15,10))
The value printed by the code snippet is __________ (Answer in integer)
Show answer without attempting

Loading the answer…

Q38

GATE DA 2024 DAProgramming in PythonMCQ2 marks−2/3 if wrong

Report a problem with Q38

What is wrong?
Consider the following Python code:
def count(child_dict, i):
    if i not in child_dict.keys():
        return 1
    ans = 1
    for j in child_dict[i]:
        ans += count(child_dict, j)
    return ans

child_dict = dict()
child_dict[0] = [1,2]
child_dict[1] = [3,4,5]
child_dict[2] = [6,7,8]
print(count(child_dict,0))
Which ONE of the following is the output of this code?
Show answer without attempting

Loading the answer…

Q39

GATE DA 2024 DAProgramming in PythonMCQ2 marks−2/3 if wrong

Report a problem with Q39

What is wrong?
Consider the function computeS(X) whose pseudocode is given below:
computeS(X)
S[1] ← 1
for i ← 2 to length(X)
    S[i] ← 1
    if X[i − 1] ≤ X[i]
        S[i] ← S[i] + S[i − 1]
    end if
end for
return S
Which ONE of the following values is returned by the function computeS(X) for X = [6, 3, 5, 4, 10]?
Show answer without attempting

Loading the answer…

Q41

GATE DA 2024 DAProgramming in PythonMCQ2 marks−2/3 if wrong

Report a problem with Q41

What is wrong?
Consider the following Python function:
def fun(D, s1, s2):
    if s1 < s2:
        D[s1], D[s2] = D[s2], D[s1]
        fun(D, s1+1, s2-1)
What does this Python function fun() do? Select the ONE appropriate option below.
Show answer without attempting

Loading the answer…

0/90 correct0 marks

Related topics in Programming Data Structures and Algorithms