Font size
WorksheetsCP M9 Assessment Review
Total questions: 12
Worksheet time: 10mins
How many rows are in the two-dimensional array mat?
mat = []
mat.append([0, 1, 2, 3])
mat.append([4, 5, 6, 7])
1
2
3
4
What is printed by the following code?
mat = []
mat.append([0, 1, 2])
mat.append([3, 4, 5])
mat.append([6, 7, 8])
print(mat[1][2])
0
1
4
5
In two-dimensional arrays, the _____________ is always listed second.
dimension
row
initializer list
column
What is in element [1][1]?
39
42
82
85
Consider the following code:
temp = []
temp.append ([25, 38, 47, 47, 24, 50, 20, 48, 46, 24, 21, 32, 40])
temp.append ([50, 20, 48, 46, 24, 21, 32, 40, 44, 47, 25, 22, 29])
temp.append ([21, 32, 40, 44, 47, 25, 22, 29, 26, 39, 43, 30, 49])
for r in range(len(temp)):
for c in range(len(temp[0])):
print (temp[r][c], end=' ')
print ("")
print (temp[2][3])
What is output by the last line of code?
20
32
44
48
Consider the following code:
ar = []
ar.append ([29, 21, 33, -30])
ar.append ([39, 26, -43, 42])
ar.append ([123, 43, 33, 46])
for r in range(len(ar)):
for c in range(len(ar[0])):
print (ar[r][c], end=' ')
print ("")
How many columns does the array have?
0
2
4
5
grid = []
grid.append (["frog", "cat", "hedgehog"])
grid.append (["fish", "emu", "rooster"])
print (grid[1][1])
What is output?
frog
cat
fish
emu
Two-dimensional arrays are (a) major.
What does the following code print:
mat = []
for i in range(5):
mat.append([])
for j in range(4):
mat[i].append(i * j)
print(mat)
[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6], [0, 3, 6, 9], [0, 4, 8, 12]]
[[0, 0, 0, 1], [0, 1, 2, 3], [0, 2, 4, 6], [0, 3, 6, 9], [0, 4, 8, 12]]
[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6], [0, 3, 6, 9], [0, 0, 8, 12]]
[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6], [4, 3, 6, 9], [0, 4, 8, 12]]
A ________ variable is available to all methods in a program.
global
local
In an array the index is _______________.
The location of an individual piece of data in an array
All of the data stored in an array.
The dimensions of the array
An individual piece of data stored in an array.
Which of the following lines of code will NOT correctly create a two-dimensional array?
stuff = [] stuff.append([]) stuff[0].append(7)
stuff = [] stuff.append ([1, 5, 7, 2])
stuff = [][]
stuff = [] stuff = [[3, 4, 5], [6, 3, 1]]
