WorksheetsCh. 9 Exam Review
Total questions: 20
Worksheet time: 10mins
What is wrong with the following attempt to initialize a list? data = ["hockey", 4, False]
You should be using parentheses ( ) to surround the items in a list
"data" is not a valid variable name
You can't mix different types of data in a single list
Nothing; this will work correctly
What will be displayed on the screen when the following code is run? esports = ["Donkey Kong", "Galaga", "Pac Man"] print( esports[1] )
Donkey Kong
Galaga
Pac Man
Syntax error; you can't access individual list items this way
What is wrong with the following code? esports = ("Donkey Kong", "Galaga", "Pac Man") esports[1] = "Centipede"
You cannot update an item in a tuple
The item at index 1 does not exist
The [1] notation after the variable name is not valid
Nothing; this will work fine
Given a list with 3 items, what is the lowest and highest valid index number into that list?
0 and 2
1 and 3
0 and 3
1 and 2
Given a list named "esports", which of the following statements will access only the first and second items in that list?
esports(0:1)
esports{0:2]
esports(1,2)
esports.range(0,2)
What is displayed on the output screen when the following code runs? esports = ("Donkey Kong", "Galaga", "Pac Man") print(len(esports))
3
('Donkey Kong', 'Galaga', 'Pac Man')
esports
Error; the len() function will not work on a tuple
What is displayed to the screen when the following code runs? esports = ["Donkey Kong", "Galaga", "Pac Man"] esports.insert(0,"Centipede") print(esports)
['Centipede', 'Galaga', 'Pac Man']
['Donkey Kong', 'Galaga', 'Pac Man', 'Centipede']
['Centipede', 'Donkey Kong', 'Galaga', 'Pac Man']
['Centipede', 'Centipede', 'Centipede']
What is displayed to the screen when the following code runs? esports = ["Donkey Kong", "Galaga", "Pac Man"] esports.reverse() print(esports)
['Pac Man', 'Galaga', 'Donkey Kong']
['Donkey Kong', 'Galaga', 'Pac Man']
['gnoK yeknoD', 'alagaG', 'naM caP']
Error; you cannot use the reverse() function on a list
What is displayed on the screen when the following code runs? esports = ["Donkey Kong", "Galaga", "Pac Man"] item = esports.pop(0) print(esports)
['Galaga', 'Pac Man']
['Donkey Kong', 'Galaga', 'Pac Man']
['Donkey Kong']
['Donkey Kong', 'Galaga']
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")
Found it
Not here
Both "Found it" and "Not here"
Nothing - there is no output at all
Given a list named "esports", which of the following statements would allow you to iterate through each item in the list?
for sport in esports
for i in range(0,3)
while (esports)
for sport range(esports)
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'
['Donkey Kong', 'Galaga', 'Pac Man']
['Centipede', 'Centipede', 'Centipede']
['Centipede','Donkey Kong', 'Galaga', 'Pac Man']
Error, you cannot iterate over a list with this "for" statement
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'
['Centipede', 'Centipede', 'Centipede']
['Donkey Kong', 'Galaga', 'Pac Man']
['Centipede','Donkey Kong', 'Galaga', 'Pac Man']
Syntax error; you cannot use the [i] format to access items in a list
What will be displayed to the screen when the following code runs? esport = "Galaga" for letter in esport: print(letter + "_",end="")
G_a_l_a_g_a_
Galaga
_ _ _ _ _ _
Error; you cannot iterate over the letters in a string using the "in" keyword
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 ]
Binary search
Sequential search
Both of these would work
Neither of these would work
Which of the following best describes the sequential search algorithm?
One for() loop that compares each element in sequence until the target value is found
One while() loop that randomly selects an index within the list and compares that value, continuing until the value is found
One for() loop that discards half of the target list on each step
Nested for() loops that will swap elements until the target values is located at the front of the list
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 ]
5
7
2
The sequential search cannot be run on unsorted data
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?
(highIndex + lowIndex) // 2
lowIndex + 1
highIndex - 1
highIndex - lowIndex
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 ]
8
2
4
The binary search cannot be used on sorted data
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?
8
4
100
50
