Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

[AP CSP] Programming: LISTS/ARRAYS (Python)

Total questions: 16

Worksheet time: 16mins

Name
Class
Date
1.

people = ["John", "Rob", "Bob"]

print (people[1])

what would this result be?

a)
John
b)
Rob
c)
Bob
2.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

d)

nameList = [John, Harry, Jesse, John, Harry, Harry]

3.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Jeremy", "Tom"]

a)

"John"

b)

"Harry"

c)

"Jesse"

d)

"Jeremy"

4.

Which of these pieces of code would return the name "Harry" from the following list?

nameList = ["John", "Harry", "Jesse", "John", "Grace", "Harry"]

a)

nameList(5)

b)

nameList[-5]

c)

NameList(4)

d)

nameList[6]

5.

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"]

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

6.

Which symbols are used to open and close a list?

a)

( ) round brackets

b)

( ) curly brackets

c)

[ ] square brackets

d)

" " speech marks

7.
Data type for a whole number
a)
String
b)
Integer
c)
Boolean
d)
Float
8.
A data type consisting of numbers, letters and symbols.
a)
String
b)
Integer
c)
Float
d)
Boolean
9.
A location in memory used to store data that can be changed.
a)
Constant
b)
Value
c)
Variable
d)
Iteration
10.

Which of these assigns a list to a variable?

a)

fruit = input(["apples", "oranges", "bananas"])

b)

fruit = ["apples", "oranges", "bananas"]

c)

fruit == ["apples", "oranges", "bananas"]

d)

fruit["apples", "oranges", "bananas"]

11.

To insert an item in the first position of a list we use

a)

fruit.append("strawberries, 1")

b)

fruit.insert("strawberries",0)

c)

fruit.insert(1, "strawberries")

d)

fruit.insert(0, "strawberries")

12.

An empty list can be declared as

a)

fruitList = ""

b)

fruitList = ["empty"]

c)

fruitList == []

d)

fruitList = []

13.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
14.
What output will this code produce?
a)
red
b)
['blue', 'green', 'red']
c)
['red', 'green', 'blue']
d)
error
15.

Which colour will be replaced with yellow?

a)

red

b)

green

c)

blue

d)

none, yellow will be added to the list

16.
The first element in an array is always element 1.
a)
False
b)
True