Python-For Data Science _ COMPLETE PRACTICE SHEET
Python-For Data Science _ COMPLETE PRACTICE SHEET
GATE
COMPLETE PRACTICE
Practice Set-01 SHEET
Data Science & Artificial Intelligence & NIC - PARAM
Python-For Data Science
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 1/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
that seems to modify it actually creates a Q11 Consider the following python code and
new instance. identify the output:
(B) An immutable data type can be changed print(15 // 3) 5
after it has been created without creating a print(15 / 3) 5.0
new instance.
Q12 Consider the following python code and
(C) An immutable data type means that you
identify the output:
can only ever have one variable of this type
print(5 * 5) 25
in your program. 27.5
print(5.5 * 5)
(D) An immutable data type means that no
variable can be of this type. Q13 Consider the following python code and
identify the output:
Q8 What is the relationship between the values
x = 11
"25" and 25?
y=2
(A) They are of the same type since they both
result = x % y 1
represent the number 25.
print(result)
(B) They are of different types: "25" is a string,
and 25 is an integer. Q14 Consider the following python code and
(C) They have different types, but they are identify the output:
interchangeable because Python treats print(17 // 3 + 1.5) 6.5
them as equivalent values.
(D) They're both funnier than 24. Q15 Which of the following statements is/are TRUE?
(A) The input() function always reads what the
Q9 How does the int() function work? user typed in as a string.
(A) int() always rounds up to the nearest integer (B) Escape sequences in Python are used to
value. represent special characters, and
(B) int() rounds to the nearest integer value, they always start with the backslash.
always rounding up if the decimal part is (C) The ord() function returns the ASCII code
greater than or equal to 0.5. (number) of a character.
(C) int() truncates the decimal part of float and (D) The + and * operators can be used on
returns the whole number part. strings.
(D) int() rounds to the nearest integer value, but
if the decimal part is exactly 0.5, it rounds to Q16 Which of the following statements is/are
the nearest even integer. INCORRECT?
(A) The format() function always generates an
Q10 Consider the following python code and integer representation of whatever you give
identify the output: it.
m=4 (B) x ** y is different from pow(x, y).
n=6 (C) The chr() function returns the character
m, n = n, m corresponding to a given ASCII code.
print(m, n) 6, 4 (D)
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 2/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
To use functions like max() and min(), you do operation value2 = value + 5 without an error?
not need to import the math module. (A) Yes, it will work without any issues.
(B) No, it will result in a runtime error.
Q17 Consider the following statements:
(C) Yes, but value2 will be “255”.
S1: To convert a letter from upper to lower, you
(D) None of These
can add 32 to its ASCII value.
S2: The print() and format() functions are Q22 What is the result of the following code?
interchangeable in all cases. s1 = “pqr”
Which of the following is CORRECT? s2 = “def”
(A) Only S1 is correct. result = s1 * 3 + s2
(B) Only S2 is correct. print (result)
(C) Both S1 and S2 are correct. (A) “pqrpqrpqrdef”
(D) Neither S1 nor S2 are correct. (B) “s1s1s1s2”
(C) “pqr333def”
Q18 What is a possible result from random ()? (0,1)
(D) Error
(A) 0.5 (B) 0
(C) 1 (D) Any of A, B, C Q23 Write the output:
error since 0.if is not valid
print (format (421.698, “0.if”)) 0.2f is valid for precision
Q19 Which of the following correctly match the
escape sequences for tab, newline, and Q24 Write the output:
backslash? print(max (–30, 10, 27, –3) + min(–30, 10, 27, –3) -3
(A) \tt, \new, \\\ (B) \t, \n, \\
Q25 Write the output:
(C) \tab, \n1, \\\ (D) \tab, \n, \\ error chr('y') return 'y' and -
letter = ‘y’ 6 does not work on that
Q20 What is the difference between the end and print (chr (letter) – 6), chr (ord(letter) – 34))
sep parameters in the print () function?
Q26 Write the output:
(A) end specifies the separator between
x=6
successive arguments; sep specifies the
y = 11
string added at the end of the printed
z = 16 11-6-16!
output.
print (y, x, z sep = “ –”, end = “!”)
(B) end specifies the separator between
successive arguments; sep specifies the Q27 Write the output: ' 20'+"\\\\" = ' 20\\\\'
string added before each argument. print(format (20.2, “>5. 0f”) + “\\\\”)
(C) sep specifies the separator between
successive arguments; end specifies the Q28 Which of the following statements is/are TRUE?
string added at the end of the printed
output. (A) bool("True") evaluates to True.
(D) None of These (B) bool("False") evaluates to False.
(C) "True" and True are different types of
Q21 If we execute the code value = input() and the objects.
user enters 25, can we then perform the (D)
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 3/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
The only possible Boolean values are True, Q34 When would you typically use a conditional
False, and None. expression in Python?
(A) When you need to execute a block of code
Q29 Which of the following statements is/are TRUE?
repeatedly.
(A) None and "None" are equivalent.
(B) When you need to iterate over a known
(B) The order of the conditions in an if-elif-else
sequence of elements.
block does not matter.
(C) When you need to assign a value based on
(C) The elif clause can be used multiple times
a condition.
within an if-elif-else block.
(D) When you want to handle errors and
(D) The not operator is used to reverse the
exceptions.
logical state of its operand.
Q35 What happens if none of the conditions in an if-
Q30 Which of the following statements is/are TRUE?
elif-else block are met?
(A) Nested if statements are if statements that
(A) The program terminates.
are placed inside each other, allowing for
(B) The block of code associated with the else
multiple levels of conditional execution.
statement is executed.
(B) The elif clause can only appear in an if
(C) The program moves to the next line of code
statement with an else clause.
outside the if-elif-else block.
(C) The else clause can be used outside an if
(D) An error is raised.
statement.
(D) The = operator is used to compare two Q36 When would you typically use an elif clause
values for equality, while the == operator is instead of multiple if statements?
used to assign a value to a variable. (A) When you want to provide a default block of
code to execute when none of the previous
Q31 Can a variable declared within an if statement
conditions are met.
be accessed outside of that if statement?
(B) When you have multiple conditions to check,
(A) Yes, it can.
but only one of them should be executed.
(B) No, it cannot.
(C) When you need to execute a block of code
(C) It depends on whether the declaration
repeatedly.
executes.
(D) When you want to handle specific cases
(D) Only if the variable is defined as global.
within a larger set of conditions.
Q32 What is the result of the logical operation True
Q37 Consider the expression x >= 0 or y < 10. If we
and False?
assume x is equal to 10, and y is equal to 5, then
(A) True (B) False
Python will evaluate.
(C) None (D) Error
(A) Python will evaluate both conditions in left-
Q33 Which logical operator in Python returns True if right order to determine whether the
at least one of the operands is True? expression is True.
(A) and (B) or (B) Python will evaluate both conditions in right-
(C) not (D) is left order to determine whether the
expression is True.
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 4/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 5/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
Q47 Which of the following statements is/are TRUE? The range() function can generate both
(A) The break statement can be used to exit a continuous and non-continuous sequences
loop prematurely of numbers in ascending or descending
(B) It is possible to use the break statement to order.
exit multiple nested loops at once. (D) The range() function can only be used with
(C) The continue statement is used to skip the for loops and not with while loops.
remaining code within the current iteration
Q51 When would you typically use a while loop
of a loop and move to the next iteration.
instead of a for loop?
(D) The sequence generated from range(n),
(A) When you need to iterate over a known
where n is an integer, starts at 1 and goes up
sequence of elements.
to (but does not include) n.
(B) When the number of iterations is fixed and
Q48 Which of the following statements is/are TRUE? predetermined.
(A) Nested loops require using both for and (C) When the loop requires an exit condition
while loops. that is not based on the number of
(B) Infinite loops occur when the condition iterations.
controlling the loop never becomes False or (D) When you want to execute a block of code
when there is no exit from loop body. at least once.
(C) The while loop in Python is always
Q52 What is the purpose of nested loops?
guaranteed to execute at least once.
(A) Nested loops allow for more efficient
(D) A while True loop will run indefinitely until a
memory utilization.
break statement is encountered.
(B) Nested loops are used to handle errors and
Q49 Consider the following statements: exceptions that may occur during loop
S1: The loop condition in a while loop is execution.
evaluated before each iteration. (C) Nested loops enable complex patterns of
S2: The loop control variable in loops like for x in iteration by placing loops inside each other.
range(2) can be accessed outside the loop.
Which of the following is CORRECT? (D) Nested loops have no purpose. You can use
(A) Only S1 is correct. a single loop in any instance you use nested
(B) Only S2 is correct. loops.
(C) Both S1 and S2 are correct.
Q53 In a for loop statement like for x in range(3), can
(D) Neither S1 nor S2 are correct.
you modify the value of the loop variable x
Q50 Which of the following statements about the within the loop body to change the number of
range() function in Python is true? iterations?
(A) The range() function can generate (A) Yes, the loop variable x can be modified
sequences of both numbers and strings. within the loop body to change the number
(B) The range() function provides an option for of iterations.
randomization in for loops. (B) No, modifying the loop variable x directly
(C) within a for loop will not a affect the number
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 6/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
of iterations. count = 0
(C) Modifying the loop variable x will cause an while count < 5:
error and terminate the loop. print(count, end=" ")
(D) The loop variable x can only be modified if count == 2:
012
indirectly using additional variables. break
count += 1
Q54 What is the main difference between loops and
conditionals (if/elif/else) in programming? Q58 Consider the given code and identify the
(A) Loops are used to execute a block of code output
repeatedly, while conditionals are used to for i in range(1, 10, 2):
make decisions based on different print(i, end=" ") 13579
conditions.
Q59 Consider the given code and identify the
(B) Loops and conditionals are interchangeable
output
and can be used interchangeably in any
num = 10
programming scenario.
while num > 0:
(C) Conditionals cannot be nested inside other
if num % 2 == 0: will go into infinite loop
conditionals, but loops can be nested inside
num -= 1
other loops.
else:
(D) Conditionals are used to iterate over a
num += 1
sequence of values, while loops are used to
print(num, end=" ")
check for specific conditions and execute
code accordingly. Q60 Consider the given code and identify the
output
Q55 Consider the given code and identify the
my_sum = 0
output
for i in range(1, 5):
count = 1
my_sum += i 1+2+3+4
while count <= 10:
print(i)
if count % 3 == 0: 1 2 4 5 7 8 10
count += 2 Q61 Consider the given code and identify the
continue output
print(count, end=" ") x = 10
count += 1 while x in range(10, 5, -2):
print("Python", end = " ") python python
Q56 Consider the given code and identify the
x -= 4
output
for i in range(4): Q62 Which of the following statements is/are TRUE?
123345
for j in range(i): (A) A function must always have a return
print(i + j, end=" ") statement.
(B) A variable defined within a function is limited
Q57 Consider the given code and identify the
to that function and is not accessible
output
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 7/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 8/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 9/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
(D) To loop over the indices of string s, you can Q83 If s = “Padhle and Beta =)", what is the result of
do for i in range(len(s) + 1). the expression len(s) - len(s.replace(" ", ""))?
(A) 0
Q78 Which of the following statements is/are TRUE?
(B) 1 3
(A) Strings in Python are 0-based indexed (i.e.,
(C) 2
the first character is at index 0).
(D) None of the above
(B) The strip() method in Python removes both
leading and trailing whitespace from a Q84 Which of the following statements is true about
string. Python strings?
(C) Python allows you to compare strings using (A) Strings can only contain letters and numbers.
the relational operators (<, <=, >, >=) based (B) Strings can be modified in place.
on their lengths. (C) Strings must always be enclosed in double
(D) Strings can indexed using negative quotes.
numbers. (D) Strings can be converted to other data
types.
Q79 Consider the following statements:
S1: On string s, min(s) == max(s) will always Q85 What does the replace() method do when
evaluate to False. applied to a string?
S2: islower(), isdigit() and isalpha() are all (A) It removes all whitespace from the string.
functions, so they take a string as a parameter (B) It replaces all occurrences of one substring
rather than being directly called on a with another.
string. (C) It reverses the characters in the string.
S3: When s is a string, in loops like for i in s, i will (D) It raises an error since strings are immutable.
refer to a character of s each iteration.
Q86 If you want to traverse through a string S using
How many of the above statement is/are
negative indices in Python, which loop should
CORRECT?
you use?
Q80 What is the result of "ink ink" * 2 + " ink"? (A) for i in range(-1, -len(S)-1, -1)
(A) "ink inkink ink ink" (B) for i in range(len(S))
(B) "ink inkink" (C) for i in range(-len(S), 0, -1)
(C) "ink ink ink ink" (D) for i in range(-len(S), 0)
(D) None of the above
Q87 If s is a string, which expression will always
Q81 What is the result of “Feebee".find("e")? evaluate to True?
(A) 1 (B) 2 (A) chr(ord(s))) == s
(C) 4 (D) 5 (B) s.upper().lower() == s
(C) s[0:len(s)] == s
Q82 Which operator can be used to check if a
(D) All of the above
substring is present in a string?
(A) contains (B) in Q88 Write the output of the following code:
(C) exists (D) substring s = “PythonPadlo"
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 10/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
print(string1, string2)
Q89 Write the output of the following code:
s = "SillyPython-561" Q93 Write the output of the following code:
result = "" myGateExam = “DataScience" # =)
for char in s: print(myGateExam[0:1000] * 2)
DataScienceDataScience
if char in str(not s):
Q94 Write the output of the following code:
result += "B"
elif char.isalpha():
alpha, beta = "cast", "dean"
result += char.upper() deancas, dest
omega = beta[:2] + alpha[2:]
elif char.isdigit():
sigma = beta[:len(beta)] + alpha[:3]
result += str(int(char) + 3)
print(min(omega, sigma), max(omega, sigma))
else:
result += char Q95 Which of the following statements is/are TRUE?
print(result) SILLYPYTHON-894
(A) Comparing two lists of different lengths will
result in an error.
Q90 Write the output for the following code:
(B) It is possible to directly convert a list to a
s = “ShakalakaBoom"
string in Python
result = (s[-len(s):-len(s)+5] + " " + s[-6:])
(C) The append() method adds an element to
print(result)
Shaka kaBoom the beginning of a list in Python.
Q91 Write the output of the following code (D) The expression [x for x in range(10) if not x %
javascript = “doobyD00by" 2] creates a list containing only positive even
python = “hurrah732h" integers.
ruby = "+25"
Q96 Which of the following statements is/are TRUE?
(A) Lists cannot be negatively indexed.
pankaj = python.islower() and python[999:9999]
(B) The remove() method deletes an element at
== ""
a specified index from a list. element
neeraj = ruby.isalnum() and ruby.isdigit()
(C) It is possible to convert items of other types
kamal = javascript[6:8].isdigit() and
directly to a list in Python.
javascript.count("o") == 2
(D) Lists can only contain items of the same
data type
print(pankaj, Neeraj, kamal) True, False, True
Q97 Consider the following statements:
Q92 Write the output fo the following code:
S1: The += operator in Python can be used to
def gateExam(subject1, subject2):
concatenate two lists.
subject1 = subject1 + subject2
subject2 = subject1
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 11/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
S2: Lists have a fixed maximum size, and once (B) [“Dairymilk, "Kookie", "KitKat"]
this size is reached, no more elements can be (C) ["Kookie, "KitKat", “Turbo"]
added to the list. (D) Error
S3: The pop() method in Python is used to
Q102 In Python, when comparing two lists using the
remove and return the last element of a list.
greater-than (>) or less-than (<) operators, how
How many of the above statement is/are
is the comparison evaluated?
CORRECT?
(A) The comparison checks if the lengths of the
Q98 What is the primary difference between the list lists are greater than or less than each other.
methods .append() and .extend()? (B) The comparison checks if the elements of
(A) .append() is used to add a single element to the lists, when converted to strings, are
the end of the list, while .extend() is used to greater than or less than each other in
add multiple elements to the end of the list. lexicographical order.
(B) .extend() is used to add a single element to (C) The comparison checks if the elements at
the end of the list, while .append() is used to corresponding indices in the lists are greater
add multiple elements to the end of the list. than or less than each other.
(C) .append() is used for merging two lists, while (D) List comparison using > or < is not allowed in
.extend() is used to add a single element to Python.
a list.
Q103 What is the difference between the .find() and
(D) None of These
.index() methods in Python?
Q99 Which of the following list comprehensions is (A) .find() works only on strings and returns -1 if
not valid in Python? all valid the specified element is not found, while
(A) [x for x in range(0)] .index() works on strings and lists but raises
(B) [x**2 for x in range(5) if x % 2 == 0] an error if the specified element is not found
(C) [len(item) for item in ["my", "anaconda", (B) .find() only works on lists, and .index() only
"don't"]] works on strings, but both return -1 if the
(D) [x if x > 0 else -1 for x in range(5)] specified element is not found.
(C) .find() and .index() are interchangeable
Q100 Assuming list1 is a list, which of the following
methods, and there is no significant
declarations will not create a new list object
difference between them.
with the same items as list1?
(D) .find() works on strings and lists, while .index()
(A) list2 = list1[0:len(list1)]
works only on strings, but
(B) list3 = list1
both raise an error if the specified element is
(C) list4 = [goodies for goodies in list1]
not found.
(D) list5 = list(list1)
Q104 Which of the following statements accurately
Q101 Assuming myChocolate = [“Dairymilk", "Kookie",
describes the uses of list()?
"KitKat", “Turbo"], what does the ex-pression
(A) list() is used to create an empty list.
myChocolate[:-2] evaluate to?
(B) list() can convert a string into a list, where
(A) [“Dairymilk, "Kookie"]
each character becomes an element
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 12/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
(C) list() can convert other iterable objects like a super = ["python"]
range (from range()) into lists. name = [“rohit", “dev", “aadi"]
(D) All of the above. for food in range(len(super)):
super.append(name[food])
Q105 Write the output of the following code:
print(super)
school = [“pankaj", “neeraj", “kamal"] 'python', 'rohit'
school2 = school Q112 Write the output of the following code:
school2.append(“fill") lst1 = [“Pankaj", “Neeraj"]; lst2 = [“PadhloBeta",
print(school) fill will also be added to school “GateNikalanaHaiTo"] element wise lexicographical
list comparision
print(min(max(lst1, lst2)))
Q106 Write the output of the following code:
Neeraj
Q113 Write the output of the following code:
doubleTrouble = [“july", “john", "tom", "jerry"] def iChooseYou(pc):
doubleTrouble = doubleTrouble.sort() pc.append(“Kamal")
if sorted list jerry , john, july,
print(doubleTrouble) tom but here list.sort() function pc.sort()
returns NOne faculty = [“Pankaj", “Neeraj"]
Q107 Write the output of the following code:
iChooseYou(faculty)
playground = [] kamal, neeraj, pankaj
print(faculty)
clubhouse = [“hockey", “football", “cricket",
“tennis", “badminton", “cycling"] Q114 Which of the following statements is/are TRUE?
for i in range(len(clubhouse)): (A) The expression myList[2][3] is valid for a
playground += clubhouse[i] nested list with three inner lists, each having
print(playground) at least four elements.
playground will be come same as clubhouse (B) In a linear search, if the specified item is
Q108 Write the output of the following code:
found, the search algorithm returns the index
white = [“himmat", “saahas", “budhiman"]
of the found item plus 1 to account for 0-
myFavoriteColor = [“himmat", “saahas",
based indexing.
“buddhiman"]
(C) Iterating through a nested list requires
print(myFavoriteColor is white and white ==
False and True nested loops to access each individual
myFavoriteColor)
False element.
Q109 Write the output of the following code: (D) Binary search is guaranteed to return the
answer = [“padhlo", “bacho", “rank", “aa jayegi", index of the first instance of an item in a list.
67]
Q115 Which of the following statements is/are TRUE?
answer.sort()
(A) Lists within a list can have a different length
print(answer) 67, aa jayegi, bacho, padhlo, rank
from each other.
Q110 Write the output of the following code: (B) In selection sort, the minimum element is
myNums = [1, 2, 3, 4, 5] repeatedly selected from the unsorted part
print([num ** 2 for num in myNums]) of the list and swapped with the first
1, 4, 9, 16, 25 element, while in insertion sort, elements are
Q111 Write the output of the following code:
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 13/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 14/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
Insertion sort, because it will cause Q129 Write the output of the following code:
unneeded swaps as it sorts through the gate = [["H", "X", "Z", "C"], ["A", "O", "T", "J"], \
mostly sorted list. ["K", "P", "N", "D"], ["L", "M", "U", "K"]]
(B) Selection sort, because it will unnecessarily for i in range(len(gate)):
search for minimum elements, which are for j in range(len(gate)):
H, O, N, K
likely to be in the correct place already in a if i == j:
mostly sorted list. print(gate[i][j], end = "")
(C) The two algorithms will perform exactly the
Q130 Write the output of the following code:
same.
subject = [[“python", “warehousing"], \
(D) This cannot be determined from the given
[“datascience", “mathematics", “algorithms"],
information.
\
Q125 Write the output of the following code: [“aptitude", “networking"]
queensLists = [[“ranilaxmibai"], [“ranidurgavati", teacher = [group[0] for group in subject]
“tarabai"], \ print(teacher) Python, datascience, aptitute
[“raziasultan", “padmavati",
Q131 Write the output of the following code:
“gauradevi"]]
faculty = [[“pankaj", “neeraj"], [1930, 4], [“kamal",
result = [homegirl for lst in queensLists for
“shweta", “anjali"]]
homegirl in lst] s
create a full list of all names print(facuty[-1][-2][0])
print(result)
Q132 Write the output of the following code:
Q126 Write the output of the following code:
myNums = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
inputNums = [13, 17, 25, 28, 10, 30, 21]
total = 0
myLst = [ [0, 0, 0], [0, 0, 0], [0, 0, 0] ]
for i in range(len(myNums)):
for num in inputNums: [[1 0 1],
[1 1 1], for j in range(4):
result1 = num % 3 36
[1 0 0]] if not j % 2:
result2 = (num // 10) % 3
total += myNums[i][j]
myLst[result1][result2] += 1
print(total)
print(myLst)
Q133 Which of the following statements is/are TRUE?
Q127 Write the output of the following code:
(A) Recursion is a programming technique
powerful = [[“hosiyar", “damdaar"], \
where a function calls itself.
[“budhiman", “khatarnak"], \
(B) A recursive function must have a base case
[“darpok", “shaktiman"]]
to stop the recursion.
powerful.sort()
2, 3, 1 sublists order (C) Any recursive function using a list can be
print(powerful)
adjusted to use a set.
Q128 Write the output of the following code: (D) Recursive functions are always more efficient
lst1 = [[1, -100], [5, 10]]; lst2 = [[1, -900], [999, 999]] than iterative solutions.
print(lst1 > lst2) True
Q134 Which of the following statements is/are TRUE?
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 15/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
(A) Recursive functions can be called with does not call itself repeatedly.
different parameters in each recursive call. (C) Iterative solutions are prone to errors such
(B) A recursive function can have multiple base as infinite loops, while recursive solutions are
cases. not.
(C) Recursive functions can only call themselves (D) Recursion and iteration are different
once within their body. techniques with their own strengths and
(D) Recursion is the only way to implement weaknesses, although they can be used
functions that solve certain mathematical interchangeably.
problems efficient, such as factorials.
Q138 What is the primary advantage of using
Q135 Which of the following statements is/are TRUE? recursion in programming?
(A) If function A calls function B, and function B (A) Recursion allows for more efficient memory
calls function A, then neither function is utilization.
recursive because they do not directly call (B) Recursive implementations are always
themselves. simpler because they do not use loops.
(B) Recursion always leads to infinite recursive (C) Recursion can solve complex problems
calls if not implemented correctly. concisely by breaking them down into
(C) Recursion is generally recommended for smaller instances.
problems that can be easily solved using (D) Recursion improves the speed of program
loops. execution.
(D) Recursive functions in Python cannot be (E) Recursive solutions are easier to debug.
optimized for better performance.
Q139 What is a potential drawback of using recursion
Q136 What is the purpose of a base case in a in programming?
recursive function? (A) Recursion can lead to infinite function calls
(A) To make the code more readable and and stack overflow errors.
maintainable. (B) Recursion is only applicable to
(B) To handle errors and exceptions that may mathematical calculations.
occur during recursion. (C) Recursion can be challenging with some
(C) To define the initial condition that stops the data structures, like dictionaries.
recursive calls. (D) Using recursion makes the code more
(D) To ensure that the function returns a value difficult to read and understand.
at every step of the recursion.
Q140 Which of the following is a correct recursive
Q137 Which of the following is true about the implementation of the power function?
relationship between recursive and iterative (A) def power(x, n):
solutions? if n == 0:
(A) Recursive solutions are always clearer than return 1
iterative solutions. return x * power(x, n - 1)
(B) Iterative solutions are always more efficient (B) def power(x, n):
than iterative solutions because the function if n == 1:
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 16/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 17/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
GATE
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 18/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP
81 64 GATE
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 19/19