Engineering Questions with Answers - Multiple Choice Questions

Python MCQs

1 - Question

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

  1. >>>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]

View Answer

Answer: b
Explanation: Execute in the shell to verify.




2 - Question

2. How many elements are in m?

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

a) 8
b) 12
c) 16
d) 32

View Answer

Answer: c
Explanation: Execute in the shell to verify.




3 - Question

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

  1. values = [[3, 4, 5, 1], [33, 6, 1, 2]]
  2.  
  3. v = values[0][0]
  4. for row in range(0, len(values)):
  5.     for column in range(0, len(values[row])):
  6.         if v < values[row][column]:
  7.             v = values[row][column]
  8.  
  9. print(v)

a) 3
b) 5
c) 6
d) 33

View Answer

Answer: d
Explanation: Execute in the shell to verify.




4 - Question

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

  1. values = [[3, 4, 5, 1], [33, 6, 1, 2]]
  2.  
  3. v = values[0][0]
  4. for lst in values:
  5.     for element in lst:
  6.         if v > element:
  7.             v = element
  8.  
  9. print(v)

a) 1
b) 3
c) 5
d) 6

View Answer

Answer: a
Explanation: Execute in the shell to verify.




5 - Question

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

  1. values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]
  2.  
  3. for row in values:
  4.     row.sort()
  5.     for element in row:
  6.         print(element, end = " ")
  7.     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

View Answer

Answer: d
Explanation: Execute in the shell to verify.




6 - Question

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

  1. matrix = [[1, 2, 3, 4],
  2.        [4, 5, 6, 7],
  3.        [8, 9, 10, 11],
  4.        [12, 13, 14, 15]]
  5.  
  6. for i in range(0, 4):
  7.     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

View Answer

Answer: d
Explanation: Execute in the shell to verify.




7 - Question

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

  1. def m(list):
  2.     v = list[0]
  3.     for e in list:
  4.       if v < e: v = e
  5.     return v
  6.  
  7. values = [[3, 4, 5, 1], [33, 6, 1, 2]]
  8.  
  9. for row in values: 
  10.     print(m(row), end = " ")

a) 3 33
b) 1 1
c) 5 6
d) 5 33

View Answer

Answer: d
Explanation: Execute in the shell to verify.




8 - Question

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

  1. data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
  2.  
  3. print(data[1][0][0])

a) 1
b) 2
c) 4
d) 5

View Answer

Answer: d
Explanation: Execute in the shell to verify.




9 - Question

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

  1. data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
  2.  
  3. def ttt(m):
  4.     v = m[0][0]
  5.  
  6.     for row in m:
  7.         for element in row:
  8.            if v < element: v = element
  9.  
  10.     return v
  11.  
  12. print(ttt(data[0]))

a) 1
b) 2
c) 4
d) 5

View Answer

Answer: c
Explanation: Execute in the shell to verify.




10 - Question

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

  1. points = [[1, 2], [3, 1.5], [0.5, 0.5]]
  2. points.sort()
  3. 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]]

View Answer

Answer: c
Explanation: Execute in the shell to verify.

Get weekly updates about new MCQs and other posts by joining 18000+ community of active learners