WorksheetsComputers December 13
Total questions: 25
Worksheet time: 38mins
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
print(9/3)
print("Hello" + "world!")
print("Hello" + 2 + "world")
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?
["Barry", "Harry", "Jesse", "John", "Peter", "Harry"]
"Barry"
"Harry"
"Jesse"
"John"
days = 5
if days > 6:
print(“Month”)
else:
print(“Week”)
for number in range(6):
print(number)
C
C
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
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 would the output of the program be?
thisList = ["square", "circle", "triangle", "octagon"]
if "triangle" in thisList:
print("Yes, 'triangle' is in the list")
else:
print("No triangle here!")
Yes, 'triangle' is in the list
"No triangle here!"
