Font size
WorksheetsWeek 11: Lists, Loops & "Failure"!
Total questions: 58
Worksheet time: 29mins
Is this the correct code for a list?
register = {"Sam", "Pheobe", Georgia", Richard"}
Yes
No
What is the index of “grape” in the list
[“apple”, “grape”, “orange”, “watermelon”]?
0
1
2
3
What is the output of program below?
bicycles = ['trek', 'cannondale', 'redline', 'specialized']
print(bicycles[-1])
trek
cannondale
redline
specialized
In a list called "players" if you wanted to delete the item with an index of 3 which of the following examples of code would be correct?
players.pop[2]
players.delete(2)
players.remove(2)
players.pop(2)
If you want to create an empty list called colors, which of the following pieces of code is correct?
colors = [ ]
colors = ( )
colors = { }
colours = [ ]
What will line 3 OUTPUT?
3
2
TRUE
FALSE
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList()
nameList[1]
NameList(4)
nameList["4"]
The list needs one more name added to the end - "Felipe". Which piece of code below would do this?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList.append(Felipe)
append(nameList,"Felipe")
nameList.append["Felipe",7]
nameList.append("Felipe")
Is this the correct code for a list?
register = {"Sam", "Pheobe", Georgia", Richard"}
Yes
No
Consider this list, what will be the highest index the list can have:
li=[1,2,3,4,5]
2
3
4
5
The count() method returns the number of times the specified element appears in the list.
What is the output of this code?
3
2
1
0
Output of this code?
[2,4,6,8,10]
['2','4','6','8','10']
[0,2,4,6,8]
[10,8,6,4,2]
What is the output of this code?
X
Y
Error
Which of the following functions is used to count the number of elements in a list ?
count( )
find( )
len( )
index( )
What is the index of “grape” in the list
[“apple”, “grape”, “orange”, “watermelon”]?
0
1
2
3
mylist = ["a","b"]
mylist[1] = "c"'
print(mylist)
["a","c"]
["a","b"]
["a","b","c"]
mylist
What is a list in python?
A collection of variables
A collection of items assigned to a single variable
A statement that cant be changed
A Christmas list
What is the index number for 'Spain'?
['England','Brazil','Spain','France']
0
1
2
3
Which code would i use to add an item to a list?
variable.add()
variable.append()
append.variable()
add.variable()
How do i remove something from a list?
variable.append()
variable.delete()
variable.remove()
variable=(new variable)
What is used to separate elements in a list?
Bracket
Comma
Full Stop
Space
What brackets are used to create a list?
()
[]
A condition controlled loop is...
A while loop
A for loop
Which of these operators means EQUAL TO?
'='
'=>'
'<='
'=='
What will this code do?
Print Numbers 1-11
Print Numbers 1-10
Print Numbers 2-10
Print Error
If we had a list "jointlist" that contained various integers, printing jointlist[0] would print:
The first value
The last value
The average value in jointlist
Nothing (null print)
The keyword "break":
Terminates a loop
Pauses a loop briefly
Sub-divides a memory space
Shatters reality
The built-in len() function returns:
The number of elements in a collection
The metric distance of a collection
The L2 distance of a collection
Measurements for a prismatic LENs
In Python, ranges and slices stop one short of the specified value. This annoying condition is due to:
Python being a zero-indexed language
Inaccuracy in the binary-to-decimal conversion
Perl hackers
Lisp hackers
If I wanted to reverse a string, I could slice it with:
[::-1]
[:::]
[:backward]
[.reverse()]
We use list comprehensions instead of for loops to:
Gain faster performance
Write more compact code
Flaunt our technical superiority
Engender negative feelings in weaker programmers
A while loop can be used in which of the following situations?
Repeat a set of statements till a condition remains True.
Repeat a set of statements a finite or an infinite number of times.
Iterate through a string, list, and tuple.
All of the above
Which of these is the best description of a list in Python?
A list is a collection of data that has an order and can be changed
A list is a lot of variables
A list is used for shopping
A list is a collection of data that cannot hold duplicated data and cannot be changed
In Python, the two types of loops are _____ and _______
while
for
list
if
Loop that runs till the condition is true
list
while
for
if
Kind of loop used when you know the number of times you want it to repeat
list
for
while
if
Function range(3) is equivalent to "
range(1,3)
range(0,3)
range(0,3,1)
range(1,3,0)
If you wished a loop to repeat 3 times what should you use?
For counter in range(0,5):
For counter in range(1,3):
For counter in range(0,3):
What does the '#' allow you to do?
Repeat code
Comment on code
Print code
End code
Which of these will allow me to count from 0-20 in steps of 5?
for x in range(0,20):
print(x)
while x = (0,20,5):
print(x)
for x in range(0,21,5):
print(x)
for x in range(0,21,5):
print(y)
If i want to continuously check for a correct answer, what loop would i use?
for loop
while loop
What is the error in this code?
incorrect variable name
incorrect indentation
incorrect speech marks
incorrect loop
The ............ operator is used to concatenate or join two or more strings.
+
*
&
None of the these
To place the string "strawberries" in the first position of a list we use
fruit.append("strawberries, 1")
fruit.insert("strawberries",0)
fruit.insert(1, "strawberries")
fruit.insert(0, "strawberries")
Which code would i use to add an item to a list?
variable.add()
variable.append()
append.variable()
add.variable()
How do i remove something from a list?
variable.append()
variable.delete()
variable.remove()
variable=(new variable)
What is the output of program below?
mariana_islands = ['Saipan', 'Tinian', 'Rota']
mariana_islands.remove('Tinian')
print(mariana_islands)
['Saipan', 'Tinian', 'Rota']
['Tinian', 'Rota']
['Saipan', 'Tinian']
['Saipan', 'Rota']
What is the output of program below?
mariana_islands = ['Saipan', 'Tinian', 'Rota', 'Guam']
mariana_islands.sort()
print(mariana_islands)
['Tinian', 'Saipan', 'Rota', 'Guam']
['Guam', 'Tinian', 'Rota', 'Saipan']
['Saipan', 'Rota', 'Guam', 'Tinian']
['Guam', 'Rota', 'Saipan', 'Tinian']
