Quiz
Intro to Computer Science S2 Chapter 10
This quiz has question types that open in the usual player.
Questions in this quiz (44)
1It is not possible for an array to hold an array.
- ATrue
- BFalse
2Two-dimensional array indexes are listed as [blank_start]rows[blank_end] and [blank_start]columns[blank_end]
- Arows
- Bcolumns
3Two-dimensional arrays store information that can be represented as a [blank_start]grid[blank_end]
- Agrid
4Consider the following code:
grid = []
grid.append (["frog", "cat", "hedgehog"])
grid.append (["fish", "emu", "rooster"])
print (grid)
How many rows does this array have?
[blank_start]2[blank_end]- A2
5Consider the following code:
grid = []
grid.append (["frog", "cat", "hedgehog"])
grid.append (["fish", "emu", "rooster"])
print (grid)
How many columns does this array have?
[blank_start]3[blank_end]- A3
6Consider the following code:
grid = []
grid.append (["frog", "cat", "hedgehog"])
grid.append (["fish", "emu", "rooster"])
What is output by:
print (grid[0][0])
[blank_start]frog[blank_end]- Afrog
7Consider the following code:
grid = []
grid.append (["frog", "cat", "hedgehog"])
grid.append (["fish", "emu", "rooster"])
What is output by:
print (grid[1][2])
[blank_start]rooster[blank_end]- Arooster
8Consider the following code:
grid = []
grid.append (["frog", "cat", "hedgehog"])
grid.append (["fish", "emu", "rooster"])
What is output by:
print (grid[0][1])
[blank_start]cat[blank_end]- Acat
9To iterate through (access all the entries) a two-dimensional arrays you need [blank_start]2[blank_end] for loops. (Enter the number of for loops needed).
- A2
10When using for loops and two-dimensional arrays the outside loop moves across the _____ and the inside loop moves across the ________
- Arows, columns
- Belements, indexes
- Cindexes, elements
- Dcolumns, rows
11Consider the following two-dimensional array:
What word is in [0][1]
[blank_start]will[blank_end]
- Awill
12Consider the following two-dimensional array:
What word is in [1][1]?
[blank_start]realize[blank_end]
- Arealize
13Consider the following two-dimensional array:
What word is in [3][2]?
[blank_start]fabric[blank_end]
- Afabric
14Consider the following two-dimensional array:
What word is in [2][1]?
[blank_start]bandana[blank_end]
- Abandana
15In two-dimensional arrays the ______ is always listed first
- Arow
- Bcolumn
- Cinitializer list
- Ddimension
16In Python arrays are also called ________
- Acolumns
- Blists
- Cdata
- Dinitializers
17Two-dimensional arrays are really:
- Aan array of arrays
- Bprimitive data types
- Clooped data structure
- Dbooleans
18Two-dimensional arrays are used to store data that can be represented in a _______
- Agrid
- Bstring
- Crow
- Dnumber
19Consider the following two-dimensional array called element:
What is in element [0][1]?
- Awindmill
- Bpretzel
- Cundervalue
- Drational
20Consider the following two-dimensional array called element:
What is in element [1][1]?
- Aundervalue
- Brational
- Cpretzel
- Dwindmill
21Why do we use two for loops with two-dimensional arrays?
- Ato do number calculations
- Bto correctly print out the contents
- Cone to move over the rows, and one for the columns
- Dbecause they can store both numbers and words
22Consider 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])
print (temp[1][2])
What is output?- A20
- B32
- C38
- D48
23Consider 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?- A3
- B4
- C2
- D1
24Consider the following code:
grid = []
grid.append (["frog", "cat", "hedgehog"])
grid.append (["fish", "emu", "rooster"])
print (grid[0][2])
What is output?- Acat
- Brooster
- Cemu
- Dhedgehog
25In two-dimensional arrays the ______ is always listed second
- Ainitializer list
- Brow
- Cdimension
- Dcolumn
26Consider the following two-dimensional array:
42 - 31 - 32 - 79
37 - 85 - 82 - 66
35 - 39 - 28 - 25
What is an element [2][1]- A39
- B85
- C82
- D42
27Consider the following two-dimensional array:
42 - 31 - 32 - 79
37 - 85 - 82 - 66
35 - 39 - 28 - 25
What is an element [1][1]- A82
- B42
- C39
- D85
28In an array the element is ______
- Aan individual piece of data is stored in an array
- Ball of the data stored in an array
- Cthe dimensions of the array
- Dthe location of an individual piece of data in an array
29What does it mean that arrays are row major?
- Arow comes first in the index of an element
- Bthe row comes first in the element of an index
- Cthe row comes second in the element of an index
- Dall of the data stored in rows
30To create a 2D array which of the following is NOT correct
- Astuff = []
stuff.append([1, 5, 7, 2]) - Bstuff = [][]
- Cstuff = [[3, 4, 5], [6, 3, 1]]
- Dstuff.append([])
stuff[0].append(7)
- Astuff = []
31Consider the following code:
grid = []
grid.append([63, 59, 25, 86, 86, 24, 31] )
grid.append([17, 28, 67, 68, 44, 27, 33] )
grid.append([24, 31, 28, 67, 68, 44, 27] )
What are the dimensions of the two-dimensional array?- A4x7
- B7x7
- C3x7
- D7x3
32Consider 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])
print (temp[2][1])
What is output?- A38
- B32
- C48
- D20
33Consider 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 rows does the array have?- A4
- B3
- C2
- D1
34Consider the following code:
grid = []
grid.append (["frog", "cat", "hedgehog"])
grid.append (["fish", "emu", "rooster"])
print (grid[0][2])
What is output?- Acat
- Bemu
- Chedgehog
- Dfish
35Why do we use two for loops with 2D arrays?
- Abecause they can store both numbers and words
- Bone to move over the rows, and one for the columns
- Cto correctly print out the contents
- Dto do number calculations
36Consider the following code that stores values in a 5 x 3 array called grid:
grid = []
grid.append (["frog", "cat", "hedgehog"])
grid.append (["fish", "emu", "rooster"])
grid.append (["dog", "bird", "rabbit"])
grid.append (["deer", "chipmunk", "opossum"])
grid.append (["fox", "coyote", "wolf"])
f = 0
for r in range (len (grid)):
for c in range (len(grid[0])):
f = f + 1
grid[r][c] = r * c
What is the array re-initialized to after running the code?- A2 - 2 - 2
3 - 2 - 2
4 - 3 - 2
5 - 3 - 3
6 - 4 - 3 - B0 1 2
1 2 3
2 3 4
3 4 5
4 5 6 - C0 0 0
0 1 2
0 2 4
0 3 6
0 4 8 - D1 1 1
1 2 3
1 3 5
1 4 7
1 5 9
- A2 - 2 - 2
37Which method correctly swaps two rows of an array?
- Adef swapRows (grid, a, b):
if ( a >=0 and a < len(grid)):
if ( b >=0 and b < len(grid)):
for r in range(len(grid)):
temp = grid[a][r]
grid[a][r] = grid[b][r]
grid[b][r] = temp - Bdef swapRows (grid, a, b):
if ( a >=0 and a < len(grid)):
if ( b >=0 and b < len(grid)):
for r in range(len(grid)):
temp = grid[r][a]
grid[r][a] = grid[r][b]
grid[r][b] = temp - Cdef swapRows (grid, a, b):
if ( a >=0 and a < len(grid)):
if ( b >=0 and b < len(grid)):
for c in range(len(grid[0])):
temp = grid[a][c]
grid[a][c] = grid[b][c]
grid[b][c] = temp - Ddef swapRows (grid, a, b):
if ( a >=0 and a < len(grid)):
if ( b >=0 and b < len(grid)):
for c in range(len(grid[0])):
temp = grid[c][a]
grid[c][a] = grid[c][b]
grid[c][b] = temp
- Adef swapRows (grid, a, b):
38Which loop initializes the array grid to the following values?
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15- Afor r in range (len (grid)):
for c in range (len(grid[0])):
grid[r][c] = r + 1 - Bfor r in range (len (grid)):
for c in range (len(grid[0])):
grid[r][c] = c + 1 - Cfor r in range (len (grid)):
for c in range (len(grid[0])):
grid[r][c] = r + c - Df = 0
for r in range (len (grid)):
for c in range (len(grid[0])):
f = f + 1
grid[r][c] = f
- Afor r in range (len (grid)):
39Write the code to initialize a 4 x 3 array to the values:
1 2 3
1 2 3
1 2 3
1 2 3
Assume the array called values is already declared and initialized as a 4 x 3 array.- Afor r in range (len (values)):
for c in range (len(values[0])):
values[r][c] = r + c - Bfor r in range (len (values)):
for c in range (len(values[0])):
values[r][c] = c + 1 - Cfor r in range (len (values)):
for c in range (len(values[0])):
values[r][c] = r + 1 - Dfor r in range (len (values)):
for c in range (len(values[0])):
values[r][c] = r * c
- Afor r in range (len (values)):
40Consider the following two-dimensional array:
11 25 57 97 50
67 22 45 89 38
42 12 98 73 41
88 61 82 71 62
44 27 97 54 98
88 76 77 29 66
93 12 46 12 87
95 38 82 22 35
35 26 18 83 97
73 13 26 12 94
66 42 74 78 32
53 43 10 72 10
Which loop correctly adds the values in the fourth column (i.e. the column accessed by index 3)?- Asum = 0
for r in range(len(a)):
sum = sum + a[r][3] - Bsum = 0
for r in range(len(a)):
A[r][3] = a[r][3] + sum - Csum = 0
for r in range(len(a)):
sum = sum + a[3][r] - Dsum = 0
for i in range(12):
for j in range(5):
sum = sum + a[r][c]
- Asum = 0
41Consider the following code:
vals = []
Which loop correctly builds a 14 x 17 array initialized to random 2-digit numbers?- Afor r in range(14):
vals.append([])
for c in range(17):
vals[r][c] = random.randint(10,99) - Bfor r in range(14):
for c in range(17):
vals[r].append (random.randint(10,99)) - Cfor r in range(17):
vals.append([])
for c in range(14):
vals[r].append (random.randint(10,99)) - Dfor r in range(14):
vals.append([])
for c in range(17):
vals[r].append (random.randint(10,99))
- Afor r in range(14):
42Row-major means:
- Athe for loop only iterates through the columns
- Bthe for loop only iterates through the rows
- Ccolumns first in the index
- Drows come first in the index
43Consider the following code:
grid = []
grid.append( [])
grid [0].append (9)
grid [0].append (7)
grid [0].append (5)
grid [0].append (3)
grid.append( [])
grid [1].append (2)
grid [1].append (8)
grid [1].append (1)
grid [1].append (3)
How many rows and columns does this array have?- A4 rows 2 columns
- B2 rows 4 columns
- C4 rows 4 columns
- D2 rows 2 columns
44A _______ variable is available to all methods in a program
- Aswap
- Btemp
- Clocal
- Dglobal
Information
- Description
- 10th grade Computer Science Quiz on Intro to Computer Science S2 Chapter 10, created by Grant Eversole on 10/05/2018.
- Author
- Grant Eversole
- Language
- English
- Views
- 0
- Tags
- Rating
- No ratings yet Rate this quiz