Python Programming: Chapter 6 Files And Exceptions

25 July 2022
4.7 (114 reviews)
23 test answers

Unlock all answers in this set

Unlock answers (19)
question
Which step creates a connection between a file and a program?
answer
Open the file
question
True/False: If the last line in a file is not terminated with a n the readline method will return without a n.
answer
True
question
Which method will return an empty string when it has attempted to read beyond the end of a file?
answer
readline
question
Which method could be used to convert a numeric value to a string?
answer
str()
question
How many types of files are there?
answer
two
question
what happens when a piece of data is written to a file?
answer
Data is copied from a variable in the RAM to a file
question
What do you call the process of retrieving data from a file?
answer
reading data
question
True/False: It is possible to create while loop that determines when the end of a file has been reached.
answer
True
question
True/False: Python allows the programmer to work with text and number files
answer
false
question
Which mode specifier will erase the contents of the file if it already exist and create it if it does not exist?
answer
'w'
question
True/False: An exception headler is a piece of code that is written using the try/except statement.
answer
True
question
True/False: The ZeroDivisionError exception is raised when the program attempts to perform a division by zero
answer
True
question
Which mode specifier will open a file but will not let you change the file or write to it?
answer
'r'
question
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
answer
False
question
Which method could be used to strip specific characters from the end of a string
answer
rstrip
question
True/False: Closing a file disconnects the communication between the file and the program
answer
True
question
What type of file access jumps directly to any piece of data in a file without reading the data that that came before it?
answer
random
question
Which of these is associated with a specific file and provides a way for the program to work with that file?
answer
file object
question
True/False: In python, there is nothing that can be done if the program tries to access a file that does not exist
answer
False
question
A __________ access file is also known as a direct access file
answer
random
question
Assume that the customer file references a file object, and the file was opened using the 'w' mode specifier. How would you write Mary Smith in the file
answer
customer.write('Mary Smith')
question
True/False: When a piece of data is read from a file, it is copied from the file into the program
answer
False
question
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
answer
True