Consider the following Python function:

def calculate_depth(t, n):

if n not in t:

return 1

depth = 1

for c in tree[n]:

depth += calculate_depth(t, c)

return depth

tree = {}

tree['A'] = ['B', 'C']

tree['B'] = ['D', 'E']

tree['C'] = ['F']

tree['D'] = []

tree['E'] = []

tree['F'] = []

print(calculate_depth(t, 'A'))

Note: t→ Tree, n→ Node, c→ Child

What is the output of the given code ______?

7
6
3
4
Difficulty Level: 1
Positive Marks: 2.00
Negative Marks: 0.66
Consider the following Python function:

def r_s(d):

total = 0

for key, value in d.items():

if isinstance(value, dict):

total += r_s(value)

elif isinstance(value, int):

total += value

return total

data = {

'a': 1,

'b': {'c': 2, 'd': {'e': 3}},

'f': {'g': 4},

'h': 5

}

print(r_s(data))

What is the output of the r_s(data) function__________?

15
Difficulty Level: 1
Positive Marks: 2.00
Negative Marks: 0.00
Consider the following Python function:

def computeD(X):

D = [0] * len(X)

for i in range(1, len(X)):

if X[i] < X[i - 1]:

D[i] = X[i - 1] - X[i]

else:

D[i] = 0

return D

X = [8, 5, 7, 4, 10]

result = computeD(X)

print(result)

Which ONE of the following values is returned by the function computeD(X) for X=[8,5,7,4,10]?

[0, 3, 0, 3, 0]
[0, 0, 3, 0, 3]
[0, 3, 2, 3, 0]
[0, 0, 0, 3, 0]
Difficulty Level: 1
Positive Marks: 2.00
Negative Marks: 0.66
Consider the following Python function:

def p_s(data):

result = []

for key, value in data.items():

if isinstance(value, list):

for v in value:

if v % 2 == 0:

result.append(v)

elif isinstance(value, dict):

result.extend(p_s(value))

return result

data = {

'a': [1, 2, 3],

'b': {'c': [4, 5], 'd': [6, 7, 8]},

'e': [9, 10]

}

output = p_s(data)

Which of the following statements are true about the final output?

[MSQ]

The output will contain the number 2
The output will contain the number 10
The length of the output will be 5
The output will be [2, 4, 6, 8, 10]
Difficulty Level: 1
Positive Marks: 2.00
Negative Marks: 0.00
Consider the following Python function:

def m_s(words):

result = []

for word in words:

transformed = word[::-1].upper()

if len(transformed) % 2 == 0:

result.append(transformed)

else:

result.append(transformed[::-1])

return result

words = ["apple", "banana", "kiwi", "cherry", "date"]

output = m_s(words)

Which of the following statements are true about the final output? [MSQ]

The output will contain the string 'ELPPA'.
The output will contain the string 'ANNAB'
The output will contain the string 'IWI'
The length of the output list will be 5.
Difficulty Level: 1
Positive Marks: 2.00
Negative Marks: 0.00
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.

It finds the smallest element in D from index s1 to s2, both inclusive.
It performs a merge sort in-place on the list D between indices s1 and s2, both inclusive.
It reverses the list D between indices s1 and s2, both inclusive.
It swaps the elements in D at indices s1 and s2, and leaves the remaining elements unchanged.
Difficulty Level: 1
Positive Marks: 2.00
Negative Marks: 0.66
Consider the python function

def m_d(d1, d2):

for key, value in d2.items():

if key in d1:

if isinstance(d1[key], dict) and isinstance(value, dict):

merge_dicts(d1[key], value)

elif isinstance(d1[key], list) and isinstance(value, list):

d1[key].extend(value)

elif isinstance(d1[key], set) and isinstance(value, set):

d1[key].update(value)

else:

d1[key] = value

return d1

dict1 = {'a': {'b': 1, 'c': 2}, 'd': [1, 2], 'e': {1, 2}}

dict2 = {'a': {'b': 3}, 'd': [3, 4], 'e': {3}, 'f': 4}

result = m_d(dict1, dict2)

Which of the following are true about the m_d function? [MSQ]

The key 'a' in result will contain the merged dictionary {'b': 3, 'c': 2}.
The key 'd' in result will contain the merged list [1, 2, 3, 4].
The key 'e' in result will contain the union of sets {1, 2, 3}.
The key 'f' in result will contain the value 4.
Difficulty Level: 1
Positive Marks: 2.00
Negative Marks: 0.00
Consider the given python code

def d_s(matrix):

n = len(matrix)

total = 0

for i in range(n):

total += matrix[i][i]

if i != n - i - 1:

total += matrix[i][n - i - 1]

return total

matrix = [

[1, 2, 3],

[4, 5, 6],

[7, 8, 9]

]

result = d_s(matrix)

Which of the following are true about the diagonal_sum function? [MSQ]

The function adds all the elements on the primary diagonal (top-left to bottom-right).
The function adds all the elements on the secondary diagonal (top-right to bottom-left).
If the matrix has an odd dimension, the middle element is counted twice.
The sum returned by the function for the given matrix will be 25.
Difficulty Level: 1
Positive Marks: 2.00
Negative Marks: 0.00
Consider the following Python function:

def fun(matrix):

if len(matrix) == 0:

return []

return list(map(list, zip(*matrix)))

What does this Python function fun() do? Select the ONE appropriate option below.

Computes the inverse of the matrix
Transposes the matrix
Flattens the matrix into a single list
Computes the determinant of the matrix
Difficulty Level: 1
Positive Marks: 2.00
Negative Marks: 0.66
What does the following Python function calculate?

def fun(arr):

x = [0] * len(arr)

x[0] = arr[0]

for i in range(1, len(arr)):

x[i] = x[i-1] + arr[i]

return x

The cumulative sum of the list arr
The average of the list arr
The maximum value in the list arr
The product of the elements in the list arr
Difficulty Level: 1
Positive Marks: 2.00
Negative Marks: 0.66
What does the following Python code snippet do?

def fun(arr):

return len(set(arr))

Counts the number of unique elements in arr
Counts the total number of elements in arr
Returns the unique elements in arr
Returns the number of duplicate elements in arr
Difficulty Level: 1
Positive Marks: 1.00
Negative Marks: 0.33
Find the result of the following function when n = 10

def fun(n, r):

return (1 - r**n) / (1 - r)

result =fun(10, 2)

1023
2047
1024
2048
Difficulty Level: 1
Positive Marks: 1.00
Negative Marks: 0.33
What is the output of this Python function?

def fun(s):

x = []

for start in range(len(s)):

for end in range(start + 1, len(s) + 1):

x.append(s[start:end])

return max(x, key=len)

result = fun("abcd")

"abcd"
"abc"
"a"
"ab"
Difficulty Level: 1
Positive Marks: 1.00
Negative Marks: 0.33
What will be the output of this Python code?

deffun(s):

parts = s.split('-')

return sum(int(part) for part in parts)

result = fun("10-20-30")

60
50
40
30
Difficulty Level: 1
Positive Marks: 1.00
Negative Marks: 0.33
What is the output of the following Python code?

def fun(s, n):

return s * n

result = fun("R", 3) + "B" + repeat_string("R", 2)

RRRRBRR
RRRBRR
RBRBRBR
RBR
Difficulty Level: 1
Positive Marks: 1.00
Negative Marks: 0.33