Introduction to Programming – Chapter 6

Your page rank:

Total word count: 718
Pages: 3

Calculate the Price

- -
275 words
Looking for Expert Opinion?
Let us have a look at your work and suggest how to improve it!
Get a Consultant

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

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.

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. Two (Text and Binary)

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

b. random

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

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

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’

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’

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

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

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

a. str

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

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

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

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.

False

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

True

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

False

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

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: The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.

True

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

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.

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: It is possible to create a while loop that determines when the end of a file has been reached.

Share This
Flashcard

More flashcards like this

NCLEX 10000 Integumentary Disorders

When assessing a client with partial-thickness burns over 60% of the body, which finding should the nurse report immediately? a) ...

Read more

NCLEX 300-NEURO

A client with amyotrophic lateral sclerosis (ALS) tells the nurse, "Sometimes I feel so frustrated. I can’t do anything without ...

Read more

NASM Flashcards

Which of the following is the process of getting oxygen from the environment to the tissues of the body? Diffusion ...

Read more

Unfinished tasks keep piling up?

Let us complete them for you. Quickly and professionally.

Check Price

Successful message
sending