Programming in Python: GATE DA Previous Year Questions

Programming in Python · Programming, Data Structures and Algorithms

10 questions · asked in 3 of 3 years (2024–2026)

MCQ 7 · MSQ 1 · NAT 21-mark 2 · 2-mark 8

2024Questions per year2026

Questions 6–10 of 10

Q6GATE 20252 marksMCQ−0.67 if 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"?

Q7GATE 20252 marksNAT
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)

Q8GATE 20242 marksMCQ−0.67 if 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?

Q9GATE 20242 marksMCQ−0.67 if wrong
Consider the function computeS(X)computeS(X) whose pseudocode is given below:

computeS(X)‾\underline{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)computeS(X) for X=[6,3,5,4,10]X=[6,3,5,4,10] ?

Q10GATE 20242 marksMCQ−0.67 if 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.

Keep practising

Topics in Programming, Data Structures and Algorithms

All DA topics ›