Introduction to Programming - Chapter 6

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

True

True/False: An exception handler is a piece of code that is written using the try/except statement.

True

True/False: Closing a file disconnects the communication between the file and the program.

False

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.

True

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.

False

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.

True

True/False: It is possible to create a while loop that determines when the end of a file has been reached.

False

True/False: Python allows the programmer to work with text and number files.

True

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.

True

True/False: The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.

False

True/False: When a piece of data is read from a file, it is copied from the file into the program.

b. Reading data

What do you call the process of retrieving data from a file? a. Retrieving data b. Reading data c. Input data d. Get data

a. Data is copied from a variable in RAM to a file.

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.

c. try/except statement

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

b. Random

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

d. read

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

a. str

Which method could be used to convert a numeric value to a string? a. str b. value c. num d. chr

b. rstrip

Which method could be used to strip specific characters from the end of a string? a. estrip b. rstrip c. strip d. remove

d. readline

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

a. 'w'

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'

b. 'r'

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'

c. File object

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

a. Open the file.

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.

b. random

A(n) _____ access file is also known as a direct access file. a. sequential b. random c. numbered d. text

d. customer.write('Mary Smith')

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')

b. Two (Text and Binary)

How many types of files are there? a. One b. Two c. Three d. Four


Set pelajaran terkait

CHAPTER 26: CARE OF PATIENTS WITH BURNS

View Set

Econ and Personal Finance Chapter 6 Test

View Set