WorksheetsCreating lists in Python
Total questions: 41
Worksheet time: 21mins
What is the purpose of an elif statement in Python? (Tick 1 correct answer)
to create a loop
to define a function
to handle multiple conditions in a selection statement
What is the correct syntax for creating a list in Python? (Tick 1 correct answer)
{"Monday", "Tuesday", "Wednesday"}
["Monday", "Tuesday", "Wednesday"]
(Monday, Tuesday, Wednesday)
What type of data structure is a list in Python? (Tick 1 correct answer)
static
dynamic
Each item within the list is referred to by an (a) , which is its position in the list. (Fill in the blank)
What will the following code print? days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] print(days[3]) (Tick 1 correct answer)
Wednesday
Thursday
IndexError
Tuesday
What will the following code print? days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] print(days[7]) (Tick 1 correct answer)
Saturday
Sunday
IndexError
In Python, which keyword allows you to create a block of code that only executes when a certain condition is true?
(a)
Which if statement would correctly check if the variable score is greater than or equal to 80? (Tick 1 correct answer)
if score >= 80:
if score > 80:
if score = 80:
if score <= 80:
Which of the following is correct when describing nested if statements? (Tick 1 correct answer)
The first condition needs to be False before the next condition can be run.
The first condition needs to be True before the next condition can be run.
The = symbol in Python is used for ... (Tick 1 correct answer)
equations.
assignment.
comparison.
What keyword is used in Python to output text to the user?
(a)
S (a) is used when there is more than one possible path for a program to follow. (Fill in the blank)
Which list method can be used to add an item to the end of a list? (Tick 1 correct answer)
list.insert()
list.add()
list.append()
list.remove()
Which list method can be used to remove the last item from a list if you do not know the index of the last item? (Tick 1 correct answer)
list.pop()
list.remove()
list.delete()
list.append()
The operation list.sort(reverse=True) sorts a list in (a) order (Fill in the blank)
What list method is used to find the index of a specific item? (Tick 1 correct answer)
list.find(item)
list.search(item)
list.index(item)
index.find(item)
is used when there is more than one possible path for a program to follow. (Fill in the blank)
(a)
Match the keyword to the definition. Select the correct keyword for: a collection of data in a particular sequence.
selection
list
data structure
index
Match the keyword to the definition. Select the correct keyword for: the location of an item or element in a list or string.
selection
list
data structure
index
Match the keyword to the definition. Select the correct keyword for: used when there is more than one possible path for a program to follow.
selection
list
data structure
index
Match the keyword to the definition. Select the correct keyword for: an organised way to store data for easy use.
selection
list
data structure
index
What is the correct way to access the first item in a list called names? (Tick 1 correct answer)
names[0]
names[1]
names{0}
names(0)
names(1)
What letter can you type in to join text and the values held by a variable in a print statement? (Tick 1 correct answer)
j
c
f
p
What is an IndexError? (Tick 1 correct answer)
when you have too many items in a list
when you refer to an index that does not exist in a list
when you have too few items in a list
when you have two of the same index values in a list
A list is a d (a) data structure that can grow or shrink as you add or remove items. (Fill in the blank)
A (a) is a data type that is a collection of characters. (Fill in the blank)
Lists are (a) , which means that their contents can be modified without having to create a new list. (Fill in the blank)
Which code would check the first character of name1 does not appear anywhere in name2? (Tick 1 correct answer)
name1[0] == name2[0]
len(name1) != len(name2)
name1[0] not in name2
Which of the following statements about strings is true? (Tick 1 correct answer)
Strings are mutable.
Strings are immutable.
Strings can only hold letters.
What code would you use if you wanted to check the value of the first letter held in the string message = "Hello"? (Tick 1 correct answer)
message[0]
message[1]
message["H"]
message[first]
If you update the value held by a string, the previous value is (a) . (Fill in the blank)
Match the terms with their definitions: Choose the term that matches this definition — a collection of characters.
operator
list
shuffle
string
immutable
Match the terms with their definitions: Choose the term that matches this definition — a symbol or word that instructs the computer to perform a calculation.
operator
list
shuffle
string
immutable
Match the terms with their definitions: Choose the term that matches this definition — not able to be changed.
operator
list
shuffle
string
immutable
Match the terms with their definitions: Choose the term that matches this definition — a collection of data in a sequence.
operator
list
shuffle
string
immutable
Match the terms with their definitions: Choose the term that matches this definition — randomly reorder the contents of a list.
operator
list
shuffle
string
immutable
What is the primary purpose of a for loop in Python? (Tick 1 correct answer)
to execute code indefinitely
to repeat a block of code a specific number of times
to handle errors in code
to define variables
What is the index of the second item in a list?
(a)
What can be used to perform calculations in Python? (Tick 1 correct answer)
variables
operators
loops
strings
Which statement about performing mathematical operations on list items in Python is true? (Tick 1 correct answer)
Items must be copied to a new variable first.
Operations are only for lists with numbers.
Operations can be performed directly on list items.
Items need to be converted to strings for operations.
What does the shuffle() function do to a list in Python? (Tick 1 correct answer)
sorts the list in ascending order
reverses the order of the list
randomly reorders the list items
removes duplicates from the list
