Python MCQs on List: SET 5

41. What will be the output of the following Python code?

>>>m = [[x, x + 1, x + 2] for x in range(0, 3)]

a) [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

b) [[0, 1, 2], [1, 2, 3], [2, 3, 4]]

c) [1, 2, 3, 4, 5, 6, 7, 8, 9]

d) [0, 1, 2, 1, 2, 3, 2, 3, 4]

Check Answer

 

Answer: b
Execute in the shell to verify.

42. How many elements are in m?

m = [[x, y] for x in range(0, 4) for y in range(0, 4)]

a) 8

b) 12

c) 16

d) 32

Check Answer

Answer: c
Execute in the shell to verify.

43. What will be the output of the following Python code?

values = [[3, 4, 5, 1], [33, 6, 1, 2]]

v = values[0][0]

for row in range(0, len(values)):

for column in range(0, len(values[row])):

if v < values[row][column]:

v = values[row][column]

print(v)

a) 3

b) 5

c) 6

d) 33

Check Answer

Answer: d
Execute in the shell to verify.

44. What will be the output of the following Python code?

values = [[3, 4, 5, 1], [33, 6, 1, 2]]

v = values[0][0]

for lst in values:

for element in lst:

if v > element:

v = element

print(v)

a) 1

b) 3

c) 5

d) 6

Check Answer

Answer: a
Execute in the shell to verify.

45. What will be the output of the following Python code?

values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]

for row in values:

row.sort()

for element in row:

print(element, end = ” “)

print()

a) The program prints two rows 3 4 5 1 followed by 33 6 1 2

b) The program prints on row 3 4 5 1 33 6 1 2

c) The program prints two rows 3 4 5 1 followed by 33 6 1 2

d) The program prints two rows 1 3 4 5 followed by 1 2 6 33

Check Answer

Answer: d
Execute in the shell to verify.

46. What will be the output of the following Python code?

matrix = [[1, 2, 3, 4],

[4, 5, 6, 7],

[8, 9, 10, 11],

[12, 13, 14, 15]]

for i in range(0, 4):

print(matrix[i][1], end = ” “)

a) 1 2 3 4

b) 4 5 6 7

c) 1 3 8 12

d) 2 5 9 13

Check Answer

Answer: d
Execute in the shell to verify.

47. What will be the output of the following Python code?

def m(list):

v = list[0]

for e in list:

if v < e: v = e

return v

values = [[3, 4, 5, 1], [33, 6, 1, 2]]

for row in values:

print(m(row), end = ” “)

a) 3 33

b) 1 1

c) 5 6

d) 5 33

Check Answer

Answer: d
Execute in the shell to verify.

48. What will be the output of the following Python code?

data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]

print(data[1][0][0])

a) 1

b) 2

c) 4

d) 5

Check Answer

Answer: d
Execute in the shell to verify.

49. What will be the output of the following Python code?

data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]

def ttt(m):

v = m[0][0]

for row in m:

for element in row:

if v < element: v = element

return v

print(ttt(data[0]))

a) 1

b) 2

c) 4

d) 5

Check Answer

Answer: c
Execute in the shell to verify.

50. What will be the output of the following Python code?

points = [[1, 2], [3, 1.5], [0.5, 0.5]]

points.sort()

print(points)

a) [[1, 2], [3, 1.5], [0.5, 0.5]]

b) [[3, 1.5], [1, 2], [0.5, 0.5]]

c) [[0.5, 0.5], [1, 2], [3, 1.5]]

d) [[0.5, 0.5], [3, 1.5], [1, 2]]

Check Answer

Answer: c
Execute in the shell to verify.

Pages  1  2  3  4  5  6  7

Leave a Comment