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…

0/30 correct0 marks

Related topics in Programming Data Structures and Algorithms