Deck 6: Files and Exceptions

Full screen (f)
exit full mode
Question
What do you call the process of retrieving data from a file?

A) Retrieving data
B) Reading data
C) Input data
D) Get data
Use Space or
up arrow
down arrow
to flip the card.
Question
Python allows the programmer to work with text and number files.
Question
Which method could be used to convert a numeric value to a string?

A) str
B) value
C) num
D) chr
Question
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
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
Closing a file disconnects the communication between the file and the program.
Question
The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.
Question
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
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
In Python, there is nothing that can be done if the program tries to access a file to read that does not exist.
Question
When a piece of data is read from a file, it is copied from the file into the program.
Question
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
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
How many types of files are there?

A) One
B) Two
C) Three
D) Four
Question
A(n) _____ access file is also known as a direct access file.

A) sequential
B) random
C) numbered
D) text
Question
Which method could be used to strip specific characters from the end of a string?

A) estrip
B) rstrip
C) strip
D) remove
Question
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
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
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
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
A(n) _______________ file contains data that has not been converted to text.
Question
The term _______________ file is used to describe a file from which the program gets data.
Question
The term _______________ file is used to describe a file to which data is written.
Question
An exception handler is a piece of code that is written using the try/except statement.
Question
Programmers usually refer to the process of _______________ data in a file as "writing data to" the file.
Question
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
A filename _______________ is a short sequence of characters that appear at the end of a filename preceded by a period.
Question
It is possible to create a while loop that determines when the end of a file has been reached.
Question
When a program needs to save data for later use, it writes the data in a(n) _______________.
Question
A(n) _______________ file contains data that has been encoded as text, using a scheme such as ASCII.
Question
A(n) _______________ access file retrieves data from the beginning of the file to the end of the file.
Question
A(n) _______________ gives information regarding the line number(s) that caused an exception.
Question
A(n) _______________ includes one or more statements that can potentially raise an exception.
Question
If the last line in a file is not terminated with a \n, the readline method will return the line without a \n.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/34
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 6: Files and Exceptions
1
What do you call the process of retrieving data from a file?

A) Retrieving data
B) Reading data
C) Input data
D) Get data
B
2
Python allows the programmer to work with text and number files.
False
3
Which method could be used to convert a numeric value to a string?

A) str
B) value
C) num
D) chr
A
4
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
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
5
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.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
6
Closing a file disconnects the communication between the file and the program.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
7
The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
8
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
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
9
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')
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
10
In Python, there is nothing that can be done if the program tries to access a file to read that does not exist.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
11
When a piece of data is read from a file, it is copied from the file into the program.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
12
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
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
13
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.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
14
How many types of files are there?

A) One
B) Two
C) Three
D) Four
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
15
A(n) _____ access file is also known as a direct access file.

A) sequential
B) random
C) numbered
D) text
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
16
Which method could be used to strip specific characters from the end of a string?

A) estrip
B) rstrip
C) strip
D) remove
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
17
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'
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
18
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.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
19
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'
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
20
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
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
21
A(n) _______________ file contains data that has not been converted to text.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
22
The term _______________ file is used to describe a file from which the program gets data.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
23
The term _______________ file is used to describe a file to which data is written.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
24
An exception handler is a piece of code that is written using the try/except statement.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
25
Programmers usually refer to the process of _______________ data in a file as "writing data to" the file.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
26
Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
27
A filename _______________ is a short sequence of characters that appear at the end of a filename preceded by a period.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
28
It is possible to create a while loop that determines when the end of a file has been reached.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
29
When a program needs to save data for later use, it writes the data in a(n) _______________.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
30
A(n) _______________ file contains data that has been encoded as text, using a scheme such as ASCII.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
31
A(n) _______________ access file retrieves data from the beginning of the file to the end of the file.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
32
A(n) _______________ gives information regarding the line number(s) that caused an exception.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
33
A(n) _______________ includes one or more statements that can potentially raise an exception.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
34
If the last line in a file is not terminated with a \n, the readline method will return the line without a \n.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 34 flashcards in this deck.