NEW
Font size
WorksheetsLoops Python
Total questions: 15
Worksheet time: 8mins
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
What is wrong with the following code?
esports = ("Donkey Kong", "Galaga", "Pac Man")
esports[1] = "Centipede"
The item at index 1 does not exist
You cannot update an item in a tuple
The [1] notation after the variable name is not valid
Nothing; this will work fine
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.reverse()
print(esports)
['Pac Man', 'Galaga', 'Donkey Kong']
['gnoK yeknoD', 'agalaG', naM caP']
['Donkey Kong', 'Galaga', 'Pac Man']
Error; you cannot use the reverse() function on a list
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 will be displayed to the screen when the following code runs? esport = "Galaga" for letter in esport: print(letter + "_",end="")
Galaga
G_a_l_a_g_a_
______
Error; you cannot iterate over the letters in a string using the "in" keyword
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
What kind of expression must be used as part of the "while" loop statement?
mathematical expression
assignment statement
logical expression
All of these will work
Which of the following best describes how many times the statements in the body of a "while" loop will run?
0, 1 or more times depending on the logical expression of the "while" statement
At least once
An infinite number of times until a "continue" statement is reached
A maximum of 10 times no matter what
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
Given the code below, which answer best describes how many times the "while" loop body will run?
answer = 0
while True:
add = int(input("Enter a positive integer to add, or 0 to quit: "))
answer = answer + add
if (add <= 0):
break print(answer)
None at all
At least once, and maybe more depending on the user's answer to the input() question
Exactly one time
An infinite number of times, because the logical expression is always True
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"]
What is wrong with the following attempt to initialize a list?
data = ["hockey", 4, False]
Nothing; this will work correctly
"data" is not a valid variable name
You can't mix different types of data in a single list
You should be using parentheses ( ) to surround the items in a list
