CNIT 155 QUESTIONS AND ANSWERS
t/f: Files persist across multiple runs of your program. - Answers -t
t/f: Opening a file with write access causes the contents of the file to be removed first. -
Answers -t
t/f: Passing a list as an argument passes a copy of the list. - Answers -f
t/f: The input function returns a boolean if the user types in true. - Answers -f
t/f: In python, the division operator (/) gives a float result, even if both of the numbers
are integers. - Answers -t
t/f: If is a legal python identifier. - Answers -f
Which of the following is true about readlines()?
A. readlines() will only read one line
B. readlines() will only work if the file is larger than RAM
C. readlines() will process the contents in order
D. readlines() will return a list - Answers -d
Which of the following is an error that occurs when the file cannot be retrieved by the
python program?
A. FileNotFoundError
B. IOError
C. FileError
D. Both A and B - Answers -d
Which of the following will remove the second value from the list sampleList?
A. del sampleList[1]
B. remove sampleList[1]
C. remove sampleList[2]
D. del sampleList[2] - Answers -a
Given a tuple t = (3, 6, 2, 4), which of the following will result in errors?
A. print(t[2])
B. t[0] = 5
C. print(max(t))
D. print(len(t)) - Answers -b
What is the output of the following print statement?
sampleList[10, 20, 30, 40, 50, 60]
print(sampleList[-2]) - Answers -50
t/f: Files persist across multiple runs of your program. - Answers -t
t/f: Opening a file with write access causes the contents of the file to be removed first. -
Answers -t
t/f: Passing a list as an argument passes a copy of the list. - Answers -f
t/f: The input function returns a boolean if the user types in true. - Answers -f
t/f: In python, the division operator (/) gives a float result, even if both of the numbers
are integers. - Answers -t
t/f: If is a legal python identifier. - Answers -f
Which of the following is true about readlines()?
A. readlines() will only read one line
B. readlines() will only work if the file is larger than RAM
C. readlines() will process the contents in order
D. readlines() will return a list - Answers -d
Which of the following is an error that occurs when the file cannot be retrieved by the
python program?
A. FileNotFoundError
B. IOError
C. FileError
D. Both A and B - Answers -d
Which of the following will remove the second value from the list sampleList?
A. del sampleList[1]
B. remove sampleList[1]
C. remove sampleList[2]
D. del sampleList[2] - Answers -a
Given a tuple t = (3, 6, 2, 4), which of the following will result in errors?
A. print(t[2])
B. t[0] = 5
C. print(max(t))
D. print(len(t)) - Answers -b
What is the output of the following print statement?
sampleList[10, 20, 30, 40, 50, 60]
print(sampleList[-2]) - Answers -50