wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CP M9 Assessment Review

Total questions: 12

Worksheet time: 10mins

Name
Class
Date
1.

How many rows are in the two-dimensional array mat?

mat = []

mat.append([0, 1, 2, 3])

mat.append([4, 5, 6, 7])

a)

1

b)

2

c)

3

d)

4

2.

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])

a)

0

b)

1

c)

4

d)

5

3.

In two-dimensional arrays, the _____________ is always listed second.

a)

dimension

b)

row

c)

initializer list

d)

column

4.

What is in element [1][1]?

a)

39

b)

42

c)

82

d)

85

5.

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?

a)

20

b)

32

c)

44

d)

48

6.

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?

a)

0

b)

2

c)

4

d)

5

7.

grid = []

grid.append (["frog", "cat", "hedgehog"])

grid.append (["fish", "emu", "rooster"])

print (grid[1][1])

What is output?

a)

frog

b)

cat

c)

fish

d)

emu

8.

Two-dimensional arrays are (a)   major.

9.

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)

a)

[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6], [0, 3, 6, 9], [0, 4, 8, 12]]

b)

[[0, 0, 0, 1], [0, 1, 2, 3], [0, 2, 4, 6], [0, 3, 6, 9], [0, 4, 8, 12]]

c)

[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6], [0, 3, 6, 9], [0, 0, 8, 12]]

d)

[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6], [4, 3, 6, 9], [0, 4, 8, 12]]

10.

A ________ variable is available to all methods in a program.

a)

global

b)

local

11.

In an array the index is _______________.

a)

The location of an individual piece of data in an array

b)

All of the data stored in an array.

c)

The dimensions of the array

d)

An individual piece of data stored in an array.

12.

Which of the following lines of code will NOT correctly create a two-dimensional array?

a)

stuff = [] stuff.append([]) stuff[0].append(7)

b)

stuff = [] stuff.append ([1, 5, 7, 2])

c)

stuff = [][]

d)

stuff = [] stuff = [[3, 4, 5], [6, 3, 1]]