Font size
WorksheetsWeek 12 - Even More Lists
Total questions: 58
Worksheet time: 32mins
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
When do you know when you come to the end of the loop?
Its states End loop
The command End is given
The indentation stops
What type of loop is used when you know how many times you want to repeat something?
A WHILE Loop
An IF function
A FOR Loop
A Variable
Which type of loop iterates until instructed otherwise?
FOR loop
WHILE loop
A condition is
a statement that is either True or False
a string
an integer
a list
Which kind of loop would be used?
I need a guessing game program that will let me keep guessing until I get the right answer.
FOR Loop
WHILE Loop
Which kind of loop would be used?
I need a program that will keep letting me add a monthly payment for 12 months.
FOR Loop
WHILE Loop
numbers = [5, 14, 9, 17]
for number in numbers:
if number % 3 == 0:
print(number)
The output will be?
17
9
14
9
17
14
17
Which two statements are used to implement iteration?
IF and WHILE
ELSE and WHILE
FOR and WHILE
IF and ELSE
The condition for a while loop to continue could include which of the following?
While something equals something
While something is greater than something
While something is True
All of these
Which of the following symbols is used in Python to mean "Equal to"?
=
!=
==
>=
Which of the following symbols is used in Python to mean "Not equal to"?
==
!=
<>
><
Which of the following symbols is used in Python to mean "Greater than or equal to"?
<=
>>
>=
=>
What will be displayed on the screen when the following code is run?
esports = ["Donkey Kong", "Galaga", "Pac Man"]
print( esports[1] )
Galaga
Donkey Kong
Pac Man
Syntax error; you can't access individual list items this way
Given a list with 3 items, what is the lowest and highest valid index number into that list?
1 and 2
0 and 2
0 and 3
3
Given a list named "esports", which of the following statements will access only the first and second items in that list?
esports(0:1)
esports(0:3)
esports[0:2]
esports.range(0,2)
What is displayed to the screen when the following code runs?
esports = ["Donkey Kong", "Galaga", "Pac Man"]
esports.insert(0,"Centipede")
print(esports)
['Centipede', 'Centipede', 'Centipede']
['Donkey Kong', 'Galaga', 'Pac Man', 'Centipede']
['Centipede', 'Donkey Kong', 'Galaga', 'Pac Man']
['Centipede', 'Galaga', 'Pac Man']
What is displayed on the screen when the following code runs?
esports = ["Donkey Kong", "Galaga", "Pac Man"]
if ("Galaga" in esports):
print("Found it")
else:
print("Not here")
Both "Found it" and "Not here"
Not here
Nothing - there is no output at all
Found it
What value is stored in the "total" variable after the following code runs?
total = 0
for i in range(1,4):
total = total + i
0
6
7
5
Which of the following statements will cause a "while" loop to immediately exit without running any more statements in the body or checking the logical expression again?
else
break
Continue
Stop
What is displayed to the screen when the following code runs?
esports = ["Donkey Kong", "Galaga", "Pac Man"]
esports.insert(2,"apple")
print(esports)
["Donkey Kong", "Galaga", "Pac Man"]
["Donkey Kong", "Galaga", "Pac Man", "apple"]
[ "apple", "Donkey Kong", "Galaga", "Pac Man"]
["Donkey Kong", "Galaga", "apple", "Pac Man"]
Loops help us remove the redundancy of code when a task has to be repeated several times.
True
False
With the break statement we can stop the loop even if the while condition is true
break
continue
names = ["Mary", "Jane"]
What is the output of print(names[1])?
(a)
nums = [10, 9, 8]
nums[2] = 0
total = nums[0] + nums[1] + nums[2]
print(total)
(a)
x = [0,1,2]
x.append(3)
x.append(4)
print(len(x))
(a)
names = ["Mary", "Jane"]
names.remove("Mary")
names.append("Freya")
print(names[1])
(a)
nums = [4, 6, 8, 10, 12, 14]
nums.pop(4)
print(nums[0] + nums[1])
(a)
nums = [4, 6, 8, 10, 12, 14]
nums.pop(4)
What is the output of print(nums[4])?
(a)
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"
word = "amazing"
For the given string, if we run word[2:5], what does it mean?
It will extract alphabets from index 2 to index 4
It will extract alphabets from index 2 to index 5
It will extract alphabets from position 2 to position 4
It will extract alphabets from position 2 to position 5
word = "amazing"
For the given string if we run word[2:5:2] what does 2 mean in this function?
It will pick only second alphabet
It will pick only two alphabets
It will pick every alternate alphabet
It will pick first two alphabets
Which brackets are used for Lists?
( )
[ ]
{ }
None of the above
Which method is used to delete a value from the list and display it also?
del()
pop()
popshow()
remove()
Which method is used to add a value at a specified position in the list?
append
extend
insert
pop
Example of ... ?
Indexing
Appending
Slicing
Concatenation
What is the output of the following list operation
aList = [10, 20, 30, 40, 50, 60, 70, 80]
print(aList[2:5])
print(aList[:4])
print(aList[3:])
[20, 30, 40, 50]
[10, 20, 30, 40]
[30, 40, 50, 60, 70, 80]
[30, 40, 50]
[10, 20, 30, 40]
[40, 50, 60, 70, 80]
None of these
What is the output of the following
aList = [5, 10, 15, 25]
print(aList[::-2])
[15, 10, 5]
[10, 5]
[25, 10]
What will be the output of the following Python code?
list1=[8,0,9,5]
print(list1[::-1])
[5,9,0,8]
[8,0,9]
[8,0,9,5]
[0,9,5]
___________method adds a single item to the end of the list.
extend( )
append( )
insert( )
Is this the correct code for a list?
register = {"Sam", "Phoebe", "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 the program below?
bicycles = ['trek', 'cannondale', 'redline', 'specialized']
print(bicycles[-1])
trek
cannondale
redline
specialized
List items are indexed, the first item has index [1], the second item has index [2], etc.
True
False
List items can be of any data type:
True
False
What is used to separate elements in a list?
Bracket
Comma
Full Stop
Space
An empty list can be declared as
fruitList = ""
fruitList = ["empty"]
fruitList == []
fruitList = []
Each item in a list has an "address" or index. The first index in a Python list is what?
1
0
a
A
mylist = ["a","b"]
mylist[1] = "c"
print(mylist)
["a","c"]
["a","b"]
["a","b","c"]
mylist
Consider this list, what will be the highest index the list can have:
li=[1,2,3,4,5]
2
3
4
5
How do i remove something from a list?
variable.append()
variable.delete()
variable.remove()
variable=(new variable)
Which code would i use to add an item to a list?
variable.add()
variable.append()
append.variable()
add.variable()
Which of the following keywords marks the begining of the function block?
Func
define
def
function
what is a string?
any numeric value
any float value
any character value
any special symbol value
Which answers below are correct for a string value in a variable?
'string'
"string"
%string%
#sring#
fruit1="kiwi"
fruit2="strawberry"
print(len(fruit1))
print(len(fruit2))
kiwi and strawberry
4
10
4 10
410
slicing string X="BOnVoyage"
print(X[0:5])
BOnVoy
BOnVo
oyage
bonvo
Slicing string
x="BOnvoyage
print(x[4: ])
BOnvo
bonvo
oyage
VOYAGE
