Worksheets[AP CSP] Programming: LISTS/ARRAYS (Python)
Total questions: 16
Worksheet time: 16mins
people = ["John", "Rob", "Bob"]
print (people[1])
what would this result be?
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", "Jeremy", "Tom"]
"John"
"Harry"
"Jesse"
"Jeremy"
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Grace", "Harry"]
nameList(5)
nameList[-5]
NameList(4)
nameList[6]
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")
Which symbols are used to open and close a list?
( ) round brackets
( ) curly brackets
[ ] square brackets
" " speech marks
Which of these assigns a list to a variable?
fruit = input(["apples", "oranges", "bananas"])
fruit = ["apples", "oranges", "bananas"]
fruit == ["apples", "oranges", "bananas"]
fruit["apples", "oranges", "bananas"]
To insert an item 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")
An empty list can be declared as
fruitList = ""
fruitList = ["empty"]
fruitList == []
fruitList = []
Which colour will be replaced with yellow?
red
green
blue
none, yellow will be added to the list
