ISE 135 Test 2
1. Consider the following code snippet. What will be stored in the list
prices after this code executes?
prices = [10.00, 15.50, 13.50, 20.15]
for i in range(len(prices)) :
prices[i] = prices[i] * 1.06
a. [10.60, 16.43, 14.31, 21.36]
b. [1.06, 1.06, 1.06, 1.06]
c. [10.00, 15.50, 13.50, 20.15]: a. [10.60, 16.43, 14.31, 21.36]
2. Given the following code snippet, what is the value of the variable
indexVal- ue?
states = ["Alaska", "Hawaii", "Florida", "Maine", "Ohio",
"Florida"] indexValue = states.index("Hawaii")
a. 1
b. -1
c. 2
d. 0: a. 1
3. Given the following code snippet, what is the value of the variable
removed- Value?
states = ["Alaska", "Hawaii", "Florida", "Maine", "Ohio", "Florida"]
removed- Value = states.pop(3)
a. Florida
b. Maine
c. 3
d. Hawaii: b. Maine
4. Given the following code snippet, what is the content of the list states?
states = ["Alaska", "Hawaii", "Florida", "Maine", "Ohio", "Florida"]
states.pop()
a. ["Hawaii", "Florida", "Maine", "Ohio", "Florida"]
b. ["Alaska", "Hawaii", "Florida", "Maine", "Ohio"]
c. ["Alaska", "Hawaii", "Florida", "Maine", "Ohio", "Florida"]
d. []: b. ["Alaska", "Hawaii", "Florida", "Maine", "Ohio"]
5. Given the following code snippet, what is
printed? nums = [1, 2, 3, 4, 5] nums2 = [5, 4, 3, 2, 1]
if nums == nums2 :
, ISE 135 Test 2
print("lists are equal")
, ISE 135 Test 2
else :
print("lists are not equal")
a. lists are equallists are not equal
b. an error occurs and nothing is printed
c. lists are equal
d. lists are not equal: d. lists are not equal
6. What is the resulting value of this code
snippet? sum([1, 2, 3, 4, 5])
a. 121
b. 15
c. 16
d. 14: b. 15
7. Which of the following statements looks for the name 'Bob' in the
list names?
Select one:
a.if "Bob" found in names : print("found Bob")
b.if names.indexOf("Bob") >= 0 : print("found Bob")
c.if names contains "Bob" : print("found Bob")
d.if "Bob" in names : print("found Bob"):
d. if "Bob" in names : print("found Bob")
8. Given the following code snippet, which statement correctly creates an
alias for the list prices?
prices = [10.00, 15.50, 13.25, 20.15]
a. values = prices
b. values[10] = prices[10]
c. values[10] = prices
d. for element in prices : values = element: a. values = prices
9. What is the value of the variable indexValue after the following code
snippet runs?
states = ["Alaska", "Hawaii", "Florida", "Maine", "Ohio",
"Florida"] indexValue = states.index("Pennsylvania")
a. -1
b. 6
, ISE 135 Test 2
c. A ValueError exception is raised.
d. 0: c. A ValueError exception is raised
10. What is the value of names after the following code segment has
run? names = [] names.append("Amy") names.append("Bob") names.ap-
pend("Peg")
names[0] = "Cy"
names.insert(0, "Ravi") names.insert(4, "Savannah")
a. ['Ravi', 'Cy', 'Amy', 'Bob', 'Peg', 'Savannah']
b. IndexError: list assignment index out of range
c. ['Ravi', 'Cy', 'Bob', 'Peg', 'Savannah']
d. ['Cy', 'Amy', 'Bob', 'Peg', 'Savannah']: c. ['Ravi', 'Cy', 'Bob', 'Peg',
'Savannah']
11. When reading a file in Python, you must specify two items:
a. a file name and file properties
b. a file name and data type
c. a file name and mode
d. a file name and size: c. a file name and mode
12. Before accessing a file, the program must:
a. open the file
b. name the file
c. read the file
d. close the file: a. open the file
13. After executing the following code snippet, what part is the file
object? infile = open("input.txt", "r")
a. "r"
b. infile
c. "input.txt"
d. input: b. infile
14. In the following code snippet, what does the "r"
represent? infile = open("input.txt", "r")
a. read
b. random
c. recursive
d. replace: a. read
1. Consider the following code snippet. What will be stored in the list
prices after this code executes?
prices = [10.00, 15.50, 13.50, 20.15]
for i in range(len(prices)) :
prices[i] = prices[i] * 1.06
a. [10.60, 16.43, 14.31, 21.36]
b. [1.06, 1.06, 1.06, 1.06]
c. [10.00, 15.50, 13.50, 20.15]: a. [10.60, 16.43, 14.31, 21.36]
2. Given the following code snippet, what is the value of the variable
indexVal- ue?
states = ["Alaska", "Hawaii", "Florida", "Maine", "Ohio",
"Florida"] indexValue = states.index("Hawaii")
a. 1
b. -1
c. 2
d. 0: a. 1
3. Given the following code snippet, what is the value of the variable
removed- Value?
states = ["Alaska", "Hawaii", "Florida", "Maine", "Ohio", "Florida"]
removed- Value = states.pop(3)
a. Florida
b. Maine
c. 3
d. Hawaii: b. Maine
4. Given the following code snippet, what is the content of the list states?
states = ["Alaska", "Hawaii", "Florida", "Maine", "Ohio", "Florida"]
states.pop()
a. ["Hawaii", "Florida", "Maine", "Ohio", "Florida"]
b. ["Alaska", "Hawaii", "Florida", "Maine", "Ohio"]
c. ["Alaska", "Hawaii", "Florida", "Maine", "Ohio", "Florida"]
d. []: b. ["Alaska", "Hawaii", "Florida", "Maine", "Ohio"]
5. Given the following code snippet, what is
printed? nums = [1, 2, 3, 4, 5] nums2 = [5, 4, 3, 2, 1]
if nums == nums2 :
, ISE 135 Test 2
print("lists are equal")
, ISE 135 Test 2
else :
print("lists are not equal")
a. lists are equallists are not equal
b. an error occurs and nothing is printed
c. lists are equal
d. lists are not equal: d. lists are not equal
6. What is the resulting value of this code
snippet? sum([1, 2, 3, 4, 5])
a. 121
b. 15
c. 16
d. 14: b. 15
7. Which of the following statements looks for the name 'Bob' in the
list names?
Select one:
a.if "Bob" found in names : print("found Bob")
b.if names.indexOf("Bob") >= 0 : print("found Bob")
c.if names contains "Bob" : print("found Bob")
d.if "Bob" in names : print("found Bob"):
d. if "Bob" in names : print("found Bob")
8. Given the following code snippet, which statement correctly creates an
alias for the list prices?
prices = [10.00, 15.50, 13.25, 20.15]
a. values = prices
b. values[10] = prices[10]
c. values[10] = prices
d. for element in prices : values = element: a. values = prices
9. What is the value of the variable indexValue after the following code
snippet runs?
states = ["Alaska", "Hawaii", "Florida", "Maine", "Ohio",
"Florida"] indexValue = states.index("Pennsylvania")
a. -1
b. 6
, ISE 135 Test 2
c. A ValueError exception is raised.
d. 0: c. A ValueError exception is raised
10. What is the value of names after the following code segment has
run? names = [] names.append("Amy") names.append("Bob") names.ap-
pend("Peg")
names[0] = "Cy"
names.insert(0, "Ravi") names.insert(4, "Savannah")
a. ['Ravi', 'Cy', 'Amy', 'Bob', 'Peg', 'Savannah']
b. IndexError: list assignment index out of range
c. ['Ravi', 'Cy', 'Bob', 'Peg', 'Savannah']
d. ['Cy', 'Amy', 'Bob', 'Peg', 'Savannah']: c. ['Ravi', 'Cy', 'Bob', 'Peg',
'Savannah']
11. When reading a file in Python, you must specify two items:
a. a file name and file properties
b. a file name and data type
c. a file name and mode
d. a file name and size: c. a file name and mode
12. Before accessing a file, the program must:
a. open the file
b. name the file
c. read the file
d. close the file: a. open the file
13. After executing the following code snippet, what part is the file
object? infile = open("input.txt", "r")
a. "r"
b. infile
c. "input.txt"
d. input: b. infile
14. In the following code snippet, what does the "r"
represent? infile = open("input.txt", "r")
a. read
b. random
c. recursive
d. replace: a. read