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 1–5 of 10

Q1GATE 20261 markMCQ−0.33 if 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?

Q2GATE 20262 marksMCQ−0.67 if wrong
A recursive function in Python is given.

 def mystery(n): 
 	if n <= 0: 
  		return 1 
 	else: 
  		return mystery(n-1) + mystery(n-2) 
Now, consider the following function call: mystery(4)

Assume that a typical runtime stack is used to manage function calls. Each function call is pushed onto the stack and removed only after it finishes execution.

Which of the following options denotes the total number of function calls (i.e., the total number of stack activations), including the initial call, to compute mystery(4)?(4)?

Q3GATE 20262 marksMSQ
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?

One or more options are correct.

Q4GATE 20262 marksNAT
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 )

Q5GATE 20251 markMCQ−0.33 if wrong
Consider the following Python declarations of two lists:

A=[1,2,3],B=[4,5,6]A = [1, 2, 3], \quad B = [4, 5, 6]

Which one of the following statements results in A=[1,2,3,4,5,6]A = [1, 2, 3, 4, 5, 6]?

Keep practising

Topics in Programming, Data Structures and Algorithms

All DA topics ›