Introduction to Programming Using Python, Y. Daniel Liang

This quiz is for students to practice. A large number of additional quiz is available for instructors from the Instructor's Resource Website.

Chapter 11 Multidimensional Lists


11.1  What will be displayed by the following code?

m = [[123], [456], [789]]
print(m[0][0])
A. 1
B. 2
C. 4
D. 7

11.2  Assume m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], what are len(m)?
A. 0
B. 1
C. 2
D. 3
E. 4

11.3  Assume m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], what are len(m[0])?
A. 0
B. 1
C. 2
D. 3
E. 4

11.4  For m = [[x, x + 1, x + 2] for x in range(0, 3)], m is _______.
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]

11.5  For m = [[x, x + 1, x + 2] for x in range(1, 9, 3)], m is _______.
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]

11.6  How many elements are in m = [[x, y] for x in range(0, 4) for y in range(0, 4)]?
A. 8
B. 12
C. 16
D. 32

11.7  Assume x = ((1, 2), (3, 4, 5), (5, 6, 5, 9)), what are len(x) are len(x[0])?
A. 2 and 1
B. 2 and 2
C. 3 and 2
D. 2 and 3
E. 3 and 3

11.8  Assume x = [[1, 2], [3, 4, 5], [5, 6, 5, 9]], what are len(x[0]), len(x[1]), and len(x[2])?
A. 2, 3, and 3
B. 2, 3, and 4
C. 3, 3, and 3
D. 3, 3, and 4
E. 2, 2, and 2

11.9  What will be displayed by the following program?

values = [[3451], [33612]]

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. 1
B. 3
C. 5
D. 6
E. 33

11.10  What will be displayed by the following program?

values = [[3451], [33612]]

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
E. 33

11.11  What will be displayed by the following program?

values = [[3451 ], [33612]]

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
E. The program prints one row 1 3 4 5 1 2 6 33

11.12  What will be displayed by the following code?

matrix = [[1234],
       [4, 5, 6, 7],
       [8, 9, 10, 11],
       [12, 13, 14, 15]]

for i in range(04):
    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
E. 3 6 10 14

11.13  What will be displayed by the following code?

matrix = [[1234],
       [4, 5, 6, 7],
       [8, 9, 10, 11],
       [12, 13, 14, 15]]

for i in range(04):
    print(matrix[1][i], end = " ")
A. 1 2 3 4
B. 4 5 6 7
C. 1 3 8 12
D. 2 5 9 13
E. 3 6 10 14

11.14  What will be displayed by the following program?

def m(list):
    v = list[0]
    for e in list:
      if v < e: v = e
    return v

values = [[3451], [33612]]

for row in values: 
    print(m(row), end = " ")
A. 3 33
B. 1 1
C. 5 6
D. 5 33
E. 33 5

11.15  What will be displayed by the following code?

data = [[[12], [34]], [[56], [78]]]

print(data[1][0][0])
A. 1
B. 2
C. 4
D. 5
E. 6

11.16  What will be displayed the following code?

data = [[[12], [34]], [[56], [78]]]

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
E. 6

11.17  What will be displayed by the following code?

points = [[12], [31.5], [0.50.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]]