Introduction To Programming - Chapter 6

25 July 2022
4.7 (114 reviews)
25 test answers

Unlock all answers in this set

Unlock answers (21)
question
c. File object
answer
Which of these is associated with a specific file and provides a way for the program to work with that file? a. Filename b. Extension c. File object d. File variable
question
b. Reading data
answer
What do you call the process of retrieving data from a file? a. Retrieving data b. Reading data c. Input data d. Get data
question
a. Data is copied from a variable in RAM to a file.
answer
What happens when a piece of data is written to a file? a. Data is copied from a variable in RAM to a file. b. Data is copied from a variable in the program to a file. c. Data is copied from the program to a file. d. Data is copied from a file object to a file.
question
a. Open the file.
answer
Which step creates a connection between a file and a program? a. Open the file. b. Read the file. c. Process the file. d. Close the file.
question
b. Two (Text and Binary)
answer
How many types of files are there? a. One b. Two c. Three d. Four
question
b. random
answer
A(n) _____ access file is also known as a direct access file. a. sequential b. random c. numbered d. text
question
b. Random
answer
What type of file access jumps directly to any piece of data in a file without reading the data that came before it? a. Sequential b. Random c. Number d. Text
question
b. 'r'
answer
Which mode specifier will open a file but will not let you change the file or write to it? a. 'w' b. 'r' c. 'a' d. 'e'
question
a. 'w'
answer
Which mode specifier will erase the contents of a file if it already exists and create it if it does not exist? a. 'w' b. 'r' c. 'a' d. 'e'
question
d. customer.write('Mary Smith')
answer
Assume that the customer file references a file object, and the file was opened using the 'w' mode specifier. How would you write the string 'Mary Smith' to the file? a. customer_file.write('Mary Smith') b. customer.write('w','Mary Smith') c. customer.input('Mary Smith') d. customer.write('Mary Smith')
question
d. read
answer
When a file has been opened using the 'r' mode specifier, which method will return the file's contents as a string? a. write b. input c. get d. read
question
b. rstrip
answer
Which method could be used to strip specific characters from the end of a string? a. estrip b. rstrip c. strip d. remove
question
a. str
answer
Which method could be used to convert a numeric value to a string? a. str b. value c. num d. chr
question
d. readline
answer
Which method will return an empty string when it has attempted to read beyond the end of a file? a. Read b. Getline c. input d. readline
question
c. try/except statement
answer
What statement can be used to handle some of the run-time errors in a program? a. exception statement b. try statement c. try/except statement d. exception handler statement
question
False
answer
True/False: If a file with the specified name already exists when the file is opened, and the file is opened in 'w' mode, then an alert will appear on the screen.
question
False
answer
True/False: When a piece of data is read from a file, it is copied from the file into the program.
question
True
answer
True/False: Closing a file disconnects the communication between the file and the program.
question
False
answer
True/False: Python allows the programmer to work with text and number files.
question
False
answer
True/False: In Python, there is nothing that can be done if the program tries to access a file to read that does not exist.
question
True
answer
True/False: The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.
question
True
answer
True/False: An exception handler is a piece of code that is written using the try/except statement.
question
True
answer
True/False: If the last line in a file is not terminated with a n, the readline method will return the line without a n.
question
True
answer
True/False: Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written.
question
True
answer
True/False: It is possible to create a while loop that determines when the end of a file has been reached.