Python Chapter 6 Review

25 July 2022
4.7 (114 reviews)
31 test answers

Unlock all answers in this set

Unlock answers (27)
question
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
When a piece of data is read from a file it is copied from the file into the program.
answer
False
question
Closing a file disconnects the communication between the file and the program.
answer
True
question
In Python there is nothing that can be done if the program tries to access a file to read that does not exist
answer
True
question
Python allows the programmer to work with text and number files.
answer
False
question
Strings can be written directly to a file with the write method but numbers must be converted to strings before the can be written.
answer
True
question
It is possible to create a while loop that determines when the end of a file has been reached.
answer
True
question
If the last line in a file is not terminated with /n the readline method will return the line without /n.
answer
True
question
Which of the following is associated with a specific file and provides a way for the program to work with that file?
answer
the file object
question
What is the process of retrieving data from a file called?
answer
reading data
question
Which of the following describes what happens when a piece of data is written to a file?
answer
The data is copied from a variable in RAM to a file.
question
Which step creates a connection between a file and a program?
answer
open the file
question
How many types of files are there?
answer
two
question
A(n)________ access file is also known as a direct access file.
answer
Random Access file
question
Which type of file access jumps directly to a piece of data in the file without having to read all the data that comes before it?
answer
Random
question
A single piece of data within a record is called a
answer
Field
question
Which mode specifier will erase the contents of a file if it already exists and create the file if it does not already exist?
answer
'w'
question
Which mode specifier will open a file but not let you change the file or write to it?
answer
'r'
question
Which method could be used to convert a numeric value to a string?
answer
str
question
Which method will return an empty string when it has attempted to read beyond the end of a file?
answer
read
question
Given that the customer file references a file object, and the file was opened using the 'w' mode specifier how would you write the strong 'Mary Smith' to the file?
answer
customer.write('Mary Smith')
question
When a file has been opened using the 'r' mode specifier ,which method will return the file's contents as a string?
answer
read
question
Which of the following is the correct way to open a file named users.txt in 'r' mode?
answer
infile = open('users.txt', 'r')
question
Which of the following is the correct way to open a file named users.txt to write it?
answer
outfile = open('users.txt', 'w')
question
When a program needs to save data for later use, it writes the data in a(n)________
answer
File
question
When data is written to a file, it is described as a(n)_______ file.
answer
Output
question
If data is retrieved from a file by a program, this is known by the term______ file.
answer
Read
question
A(n) ________ file contains data that has been encoded as text using as scheme such as ASCII.
answer
Text
question
A(n)______ access file retrieves data from the beginning of the file to the end of the file.
answer
Sequential
question
A(n) _________ file contains data that has not been converted to text.
answer
Binary
question
A filename________ is a short sequence of characters that appear at the end of a filename, preceded by a period.
answer
Extension