0% found this document useful (0 votes)
11 views

Python-For Data Science _ COMPLETE PRACTICE SHEET

Uploaded by

Rahul J2j2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Python-For Data Science _ COMPLETE PRACTICE SHEET

Uploaded by

Rahul J2j2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

12/13/23, 4:28 PM GATE_Practice Set-01_DPP

GATE

COMPLETE PRACTICE
Practice Set-01 SHEET
Data Science & Artificial Intelligence & NIC - PARAM
Python-For Data Science

Q1 Which of the following statements is/are TRUE? (C) str


(A) In Python, a variable is used to store data (D) bool
values in memory.
Q4 Which of the following variable names is not
(B) Mutable data objects in Python can be
allowed in Phython?
changed after they are created.
(A) my_var (B) _private
(C) Variables do not need to be declared with a
(C) 123_var (D) Max_value
specific data type.
(D) Python is a dynamically typed language, Q5 How does the round() function work in Python?
which means variables are untyped, and (A) round() always rounds up to the nearest
values have associated types. integer value.
(B) round() rounds to the nearest integer value,
Q2 Which of the following statements is/are
always rounding up if the decimal part is
INCORRECT?
greater than or equal to 0.5.
(A) Python variables can be assigned new
(C) round() rounds to the nearest integer value,
values of different types without any
always rounding down if the decimal part is
issues.
greater than or equal to 0.5.
(B) In Python, “types" refer to the classification
(D) round() rounds to the nearest integer value,
of data values that indicate the
but if the decimal part is exactly 0.5, it
kind of data they hold, such as integers or
rounds to the nearest even integer.
strings.
(C) Python variable names are not case- Q6 Which of the following statements accurately
sensitive, so “ VAR1" and “var1" refer to describes the mutability of the int, float, and str
the same variable. data types?
(D) Using function names like “print" and “min" (A) Mutable: int, float. Immutable : Str
as variable names in Python is (B) Mutable: int. Immutable: float str
always recommended to avoid conflicts. (C) All three are immutable.
(D) All three are mutable.
Q3 Consider the following code snippet, what will
be the type of variable z? Q7 What does it mean for a data type to be
x=7 "immutable"?
y=5 (A) An immutable data type cannot be modified
z=x/y after it has been created. Any operation
(A) int
(B) float

Android App | iOS App | PW Website

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)

Android App | iOS App | PW Website

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)

Android App | iOS App | PW Website

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.

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 4/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP

GATE

(C) Python will evaluate only the second x=5


condition, y < 10. y = 10 False
(D) Python will evaluate only the first condition, z=2
x >= 0. result = x and (x + y * z == 30) and (5 != True)
True
print(result) False
Q38 Which of the following statements is true?
(A) (x >= 5 and x < 15) is the same as (5 <= x < 15) Q44 Consider the given code and identify the
(B) (y > 0 or y < -10) is the same as y > 0 and y < output
-10 gate = None
(C) (x > 0 or x < -5 and y < 0) is the same as ((x > if gate == None and (bool(0.0) != bool(0)):
0 or x < -5) and y < 0) print(“data")
(D) A and C are both true elif not gate or (gate == "None" and
bool(“artificialIntelligence")):
Q39 Which of the following is equivalent to the
print(“science")
expression
else:
(p + q > r) and (s – t <= u)?
print(“python")
(A) (p + q > r) and not (s - t >= u)
(B) not (p + q < r) and (s – t <= u) Q45 Consider the given code and identify the
(C) (p – q <= r) and (t – s > u) output
(D) not ((p + q <= r) or (s – t > u)) De Morgan's law. python, java, program = 6, 10, 0
if python == java or not program:
Q40 What does the expression 5 + 10 * 2 // 3 - 4
program = 1
evaluate to?
elif java > python and not python:
(A) 6 (B) 7
program = 2
(C) 8 (D) 9
if program == True:
Q41 Consider the given code and identify the print(“GATE2024")
output else:
x = 10 print(“GATE2025")
y=3
Q46 Consider the given code and identify the
z = (x ** 2) % y + x // y + y 7
output
print(z)
ruby, python, perl = 5, 6, -1
Q42 Consider the given code and identify the if (ruby == 5):
output perl += 3
x=3 elif (python == 6):
y=5 True perl = 4
z = not ((x + y) == (x * y) and (x % y) == (y // x)) if (python > 0):
print(z) perl -= 1
if (ruby < 999):
Q43 Consider the given code and identify the perl + 1 2
output print(perl)

Android App | iOS App | PW Website

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

Android App | iOS App | PW Website

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

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 7/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP

GATE

outside of it. (B) return is used to exit a function and pass a


(C) You can call a function without passing any value back to the caller, while print() is used
arguments, even if it has required to display output on the console.
parameters. (C) print() is used to pass values to the caller,
(D) When a function lacks a return statement or while return is used to display output on the
includes a return statement without console.
specifying a value, it implicitly returns 0. (D) return and print() are used for the same
purpose, but return is used when working
Q63 Which of the following statements is/are TRUE?
with numerical values, and print() is used for
(A) A function can have multiple parameters
strings.
with the same name as long as they have
different default values. Q66 Which of the following is not an advantage of
(B) Keyword arguments are passed to a function using a function?
based on their order in the function's (A) Reusability of code.
parameters, while positional arguments are (B) Easier debugging and maintenance.
explicitly specified by name in the function (C) Increased program execution speed.
call. (D) Improved code organization and readability.
(C) When you pass a mutable object as an
Q67 What is a requirement for a function?
argument to a function in Python, the
(A) A function must have at least one
function can modify the object.
parameter.
(D) A break statement and a return statement
(B) A function must contain at least one return
can be used interchangeably.
statement.
Q64 Consider the following statements: (C) A function must be defined using the def
S1: Functions can have multiple return keyword.
statements, but only one of them will be (D) A function must have default values for its
executed during the function's execution. parameters.
S2: Functions can return multiple values using
Q68 What is the significance of proper indentation
the return statement followed by a comma-
in relation to functions?
separated list of values.
(A) Indentation within a function is optional and
Which of the following is CORRECT?
doesn’t affect the function's behavior.
(A) Only S1 is correct.
(B) Indentation is used to group code together
(B) Only S2 is correct.
and define the body of the function.
(C) Both S1 and S2 are correct.
(C) Indentation is used to define the end of a
(D) Neither S1 nor S2 are correct.
function.
Q65 What is the primary difference between using (D) Indentation is necessary to declare function
return and print()? parameters.
(A) Both return and print() serve the same
Q69 In which of the following scenarios would you
purpose, so you can use either one
not want to use default arguments for a
interchangeably.

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 8/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP

GATE

function? Consider the following code, and provide the


(A) When you want to simplify function calls by output error position
allowing some arguments to be omitted. def data(work, study, eat, dance): after keyword
argument
(B) When you want to minimize potential return work + study * eat * dance
confusion and ensure that function behavior print(data(work = 5, dance = 2, study = 2, 3))
is explicit.
Q74 Consider the following code, and provide the
(C) When you need the function to handle
output
different cases with varying argument
def gate():
values.
dataScience = “python" dataStructure
(D) When you want to ensure that all function
COMPScience = “dataStructure"
arguments are explicitly provided by the
return COMPScience
caller.
return dataScience
Q70 Consider the following code, and provide the myFavoriteSubject = gate() # GO CRACK GATE!!!
output print(myFavoriteSubject)
def ruby(javascript, perl, python):
Q75 Consider the following code, and provide the
return python + javascript / perl
output
language = ruby(perl = 3, python = 2, javascript
def friend():
= 6)
return “ABC", “XYZ“ ABC <3 XYZ
print(language) 2 + 6/3 = 4.0
person1, person2 = friend()
Q71 Consider the following code, and provide the print(person1, "< 3", person2)
output
Q76 Consider the following code, and provide the
def language(hindi = 7):
output
hindi *= 2 ruby!ruby!ruby!ruby! 112
def countMarks():
return hindi * 2 10 if print in def function
count = 0
javaDot = language(“ruby!") else count is not accessed
for num in range(10): outside function
python = language(language())
count += 1
print(javaDot, python)
print(count)
Q72 Consider the following code, and provide the
Q77 Which of the following statements is/are TRUE?
output
(A) Characters are a different type from strings
def color(grey):
in Python
kitkat = True
(B) If strings s1 and s2 are equivalent, the
munch = False
expression s1 in s2 will return False because
while not munch and kitkat:
“in" checks for partial matches and not the
break
complete operand length.
return grey + 5 if return inside while
then None output (C) In Python, you can directly modify a
print(color(10))
if outside while then character within a string by using the index
15
Q73 notation, like s[2] = "z".

Android App | iOS App | PW Website

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"

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 10/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP

GATE

new = "" MvqelkM^ail print(subject1 is subject2)


for char in s: string1 = “database"
new += chr(ord(char) - 3) string2 = “python" subject 1 is subject 2
print(new) gateExam(string1, string2)
database, python

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

Android App | iOS App | PW Website

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

Android App | iOS App | PW Website

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:

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 13/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP

GATE

compared and inserted into their correct (C) 3 (D) 4


positions in the sorted part of the list.
Q120 What will the list [86485, 42, 1337, 404, 777, 9000,
(C) The len() function can be used to find the
24601] look like after three iterations of the
total number of elements in a nested list.
selection sort algorithm?
(D) When using the .sort() method on nested
(A) [42, 404, 777, 1337, 9000, 24601, 86485]
lists in Python, the sorting is applied only to
(B) [42, 404, 777, 86485, 1337, 9000, 24601]
the outermost list, leaving the inner lists
(C) [42, 404, 1337, 86485, 777, 9000, 24601]
unaltered.
(D) None of the above.
Q116 Consider the following statements:
Q121 What will the list [86485, 42, 1337, 404, 777, 9000,
S1: When using the .sort() method on nested
24601] look like after three iterations of the
lists in Python, the sorting is applied only to the
insertion sort algorithm?
outermost list, leaving the inner lists
(A) [42, 404, 777, 1337, 9000, 24601, 86485]
unaltered.
(B) [42, 1337, 86485, 404, 777, 9000, 24601]
S2: In a linear search, one item is checked in
(C) [42, 404, 1337, 86485, 777, 9000, 24601]
the unexplored portion of the list each step,
(D) None of the above.
while in binary search, the search space is
cut in half with each step. Q122 How do you remove “smart" from the following
S3: In binary search, the number of “searches” nested list?:
required is at most half the length of the list. 100features = [[“cute", “intelligent", “mad"],
How many of the above statement is/are [“handsome", “quick", “clever", “smart"],
CORRECT? [“beautiful", “happy", “sad"]]
(A) 100features.remove(“smart")
Q117 In which scenario would using binary search be
(B) 100features.pop(1)
more advantageous than linear search?
(C) 100features [1].remove(“smart")
(A) Searching through a small, unsorted list.
(D) 100features [1].pop(“smart")
(B) Looking for the first occurrence of an item in
a list. Q123 How do you check if the string “stu" is present in
(C) Searching through a large, sorted list. the following nested list?:
(D) None of these myTeam = [[“pankaj", “neeraj"], [“stu", “student"],
[“shekhar", “kamal"]]
Q118 How many iterations does a linear search
(A) “stu" in x
require to find the value 616 in the list
(B) True if “stu" in [item for item in x] else False
[9, 10, 21, 41, 98, 123, 364, 616, 1218]?
(C) “stu" in x[1]
(A) 8 (B) 7
(D) “stu" in x[1:1]
(C) 6 (D) 9
Q124 On a list that is already mostly sorted, which
Q119 How many iterations does a binary search
sorting algorithm is likely to perform worse,
require to find the value 616 in the list
selection sort or insertion sort?
[8, 11, 22, 43, 88, 133, 364, 616, 1212]?
(A)
(A) 1 (B) 2

Android App | iOS App | PW Website

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?

Android App | iOS App | PW Website

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:

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 16/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP

GATE

return x if not str1:


else: return str2
return x * power(x, n - 1) elif not str2:
(C) def power(x, n): return str1
return x ** n else:
(D) def power(x, n): return ordered_concat(str1[1:],
if n == 0: str2[1:]) + max(str1[0], str2[0])
return 1 (B) def ordered_concat(str1, str2):
else: if len(str1) == 0:
return power(x, n) * x return str2
elif len(str2) == 0:
Q141 What does the term “recursion depth" refer to?
return str1
(A) The number of recursive calls made by a
else:
function.
return ordered_concat(str1[1:],
(B) The depth of nested loops in a recursive
str2[1:]) + min(str1[0], str2[0])
algorithm.
(C) def ordered_concat(str1, str2):
(C) The total number of lines in a recursive
if not str1:
function.
return str2
(D) The level of indentation in a recursive
elif not str2:
function.
return str1
Q142 Under what circumstances is it opportune to elif str1[0] < str2[0]:
use recursion in programming? return str1[0] + ordered_concat
(A) When the problem can be naturally divided (str1[1:], str2)
into smaller instances of the same problem, else:
and requires a parameter that can be return str2[0] + ordered_concat
minimized or truncated (str1, str2[1:])
(B) Only when the problem is impossible or too (D) def ordered_concat(str1, str2):
complex to solve iteratively. if len(str1) == 0:
(C) When aiming for the most memory efficient return str2
solution due to the inherent nature of elif len(str2) == 0:
recursive algorithms. return str1
(D) Whenever recursion is available as an elif str1[0] > str2[0]:
option, as it often simplifies code and return max(str1[0], str2[0]) +
enhances maintainability. ordered_concat
(str1[1:], str2)
Q143 What is the correct recursive implementation else:
for a function that takes two ordered strings as return str2[0] + ordered_concat
input and returns their (ascending) ordered (str1, str2[1:])
concatenation?
(A) def ordered_concat(str1, str2): Q144 Write the output of the following code:

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 17/19
12/13/23, 4:28 PM GATE_Practice Set-01_DPP

GATE

def lanaguage(python): else:


if python <= 0: clues.append(who)
return 531135 return clues
print(python, end = " ") inc = [“pankaj", [“neeraj", [“shweta", “anjali"]],
language(python - 2) [“kiran"]]
print(python, end = " ") print(gupchup(inc))
print(language(5)) 'pankaj', 'neeraj', 'shweta', 'anjali', 'kiran'
Q149 Write the output of the following code:
Q145 Write the output of the following code: def girlPower( arr, l, r, x):
def padhlo(beta): if r < l:
if not beta: return -1
return 0 if arr[l] == x:
elif beta[0] in "aeiouAEIOU": return l
return 1 + padhlo(beta[1:]) if arr[r] == x:
else: return r
return padhlo(beta[1:]) 4 return girlPower(arr, l+1, r-1, x)
print(padhlo(“RankLaoge")) princesses = [“anjali", “himani", “kiran",
"jasmine", “arpita", \
Q146 Write the output of the following code:
“bhumi", “saumya", “tanuja"]
def language(python):
print(girlPower(princesses, 0, len(princesses) - 1,
if len(python) == 0:
princesses[3])) 3
return ""
maxe42etag
else: Q150 Write the output of the following code:
return language(python[1:]) + python[0] def trickyPython(scarySnake):
print(language(“gate24exam")) if scarySnake == []:
return 0
Q147 Write the output of the following code:
elif scarySnake[0] % 2 == 0:
def subject(java, python):
return -scarySnake[0] +
if python == 0:
trickyPython(scarySnake[1:])
return java 567 else:
else:
-27 return scarySnake[0] +
return subject(python, java % python)
trickyPython(scarySnake[1:])
print(subejct(15, 10), subejct(12, 18), subejct(49,
scarySnake = [7, -42, 17, -99, 2, -8]
77))
print(trickyPython(scarySnake))
Q148 Write the output of the following code:
Q151 Write the output of the following code:
def gupchup(gang):
def gateExam(padhlo, beta):
clues = []
if beta == 0:
for who in gang:
return 1
if type(who) == list:
elif beta % 2 == 0:
clues.extend(gupchup(who))
ranker = gateExam(padhlo, beta // 2)

Android App | iOS App | PW Website

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

return ranker * ranker return padhlo * gateExam(padhlo beta -


else: 1)
print(gateExam(3, 4), gateExam(4, 3))

Android App | iOS App | PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 19/19

You might also like