Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Ch. 9 Exam Review

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is wrong with the following attempt to initialize a list? data = ["hockey", 4, False]

a)

You should be using parentheses ( ) to surround the items in a list

b)

"data" is not a valid variable name

c)

You can't mix different types of data in a single list

d)

Nothing; this will work correctly

2.

What will be displayed on the screen when the following code is run? esports = ["Donkey Kong", "Galaga", "Pac Man"] print( esports[1] )

a)

Donkey Kong

b)

Galaga

c)

Pac Man

d)

Syntax error; you can't access individual list items this way

3.

What is wrong with the following code? esports = ("Donkey Kong", "Galaga", "Pac Man") esports[1] = "Centipede"

a)

You cannot update an item in a tuple

b)

The item at index 1 does not exist

c)

The [1] notation after the variable name is not valid

d)

Nothing; this will work fine

4.

Given a list with 3 items, what is the lowest and highest valid index number into that list?

a)

0 and 2

b)

1 and 3

c)

0 and 3

d)

1 and 2

5.

Given a list named "esports", which of the following statements will access only the first and second items in that list?

a)

esports(0:1)

b)

esports{0:2]

c)

esports(1,2)

d)

esports.range(0,2)

6.

What is displayed on the output screen when the following code runs? esports = ("Donkey Kong", "Galaga", "Pac Man") print(len(esports))

a)

3

b)

('Donkey Kong', 'Galaga', 'Pac Man')

c)

esports

d)

Error; the len() function will not work on a tuple

7.

What is displayed to the screen when the following code runs? esports = ["Donkey Kong", "Galaga", "Pac Man"] esports.insert(0,"Centipede") print(esports)

a)

['Centipede', 'Galaga', 'Pac Man']

b)

['Donkey Kong', 'Galaga', 'Pac Man', 'Centipede']

c)

['Centipede', 'Donkey Kong', 'Galaga', 'Pac Man']

d)

['Centipede', 'Centipede', 'Centipede']

8.

What is displayed to the screen when the following code runs? esports = ["Donkey Kong", "Galaga", "Pac Man"] esports.reverse() print(esports)

a)

['Pac Man', 'Galaga', 'Donkey Kong']

b)

['Donkey Kong', 'Galaga', 'Pac Man']

c)

['gnoK yeknoD', 'alagaG', 'naM caP']

d)

Error; you cannot use the reverse() function on a list

9.

What is displayed on the screen when the following code runs? esports = ["Donkey Kong", "Galaga", "Pac Man"] item = esports.pop(0) print(esports)

a)

['Galaga', 'Pac Man']

b)

['Donkey Kong', 'Galaga', 'Pac Man']

c)

['Donkey Kong']

d)

['Donkey Kong', 'Galaga']

10.

What is displayed on the screen when the following code runs? esports = ["Donkey Kong", "Galaga", "Pac Man"] if ("Galaga" in esports): print("Found it") else: print("Not here")

a)

Found it

b)

Not here

c)

Both "Found it" and "Not here"

d)

Nothing - there is no output at all

11.

Given a list named "esports", which of the following statements would allow you to iterate through each item in the list?

a)

for sport in esports

b)

for i in range(0,3)

c)

while (esports)

d)

for sport range(esports)

12.

What will be the contents of the "esports" list after the following code runs? esports = ["Donkey Kong", "Galaga", "Pac Man"] for sport in esports: sport = 'Centipede'

a)

['Donkey Kong', 'Galaga', 'Pac Man']

b)

['Centipede', 'Centipede', 'Centipede']

c)

['Centipede','Donkey Kong', 'Galaga', 'Pac Man']

d)

Error, you cannot iterate over a list with this "for" statement

13.

What will be the contents of the "esports" list after the following code runs? esports = ["Donkey Kong", "Galaga", "Pac Man"] for i in range(0,len(esports)): esports[i] = 'Centipede'

a)

['Centipede', 'Centipede', 'Centipede']

b)

['Donkey Kong', 'Galaga', 'Pac Man']

c)

['Centipede','Donkey Kong', 'Galaga', 'Pac Man']

d)

Syntax error; you cannot use the [i] format to access items in a list

14.

What will be displayed to the screen when the following code runs? esport = "Galaga" for letter in esport: print(letter + "_",end="")

a)

G_a_l_a_g_a_

b)

Galaga

c)

_ _ _ _ _ _

d)

Error; you cannot iterate over the letters in a string using the "in" keyword

15.

Given the following starting data set, what search algorithm would you use to find a target value? [ 15, 9, 1, 14, 12, 8, 10, 6, 5, 3 ]

a)

Binary search

b)

Sequential search

c)

Both of these would work

d)

Neither of these would work

16.

Which of the following best describes the sequential search algorithm?

a)

One for() loop that compares each element in sequence until the target value is found

b)

One while() loop that randomly selects an index within the list and compares that value, continuing until the value is found

c)

One for() loop that discards half of the target list on each step

d)

Nested for() loops that will swap elements until the target values is located at the front of the list

17.

Given the following starting data set, how many steps would it take the sequential search algorithm to find the value 12? [ 15, 9, 1, 14, 12, 8, 10, 6, 5, 3 ]

a)

5

b)

7

c)

2

d)

The sequential search cannot be run on unsorted data

18.

If the binary search algorithm is using "lowIndex" and "highIndex" variables to track the current lower and upper boundaries within the list, what calculation would determine the index used to read a value from the list for comparison?

a)

(highIndex + lowIndex) // 2

b)

lowIndex + 1

c)

highIndex - 1

d)

highIndex - lowIndex

19.

Given the following starting data set, how many steps would it take for a binary search to find the number 8? [ 1, 2, 3, 4, 5, 6, 7, 8 ]

a)

8

b)

2

c)

4

d)

The binary search cannot be used on sorted data

20.

If a list has 100 elements, which answer best represents the maximum number of passes a binary search algorithm will take to find a target value?

a)

8

b)

4

c)

100

d)

50