Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTIONS ON PYTHON QUESTION 1 What happens when a program opens the same readab

ID: 3779806 • Letter: Q

Question

QUESTIONS ON PYTHON

QUESTION 1

What happens when a program opens the same readable file for reading two or more times?

All calls to the open() function return the same open file handle.

Several copies of the file are created, and each is open for reading.

The program crashes when it attempts to open the file for the second time.

Two or more open file handles are created.

QUESTION 2

What does the method .readline() return when it reads to the end of a file?

A blank line.

An empty string.

Nothing, the program crashes.

None

QUESTION 3

Match file open modes and file existence conditions to the outcomes of opening a file.

        

open(existing_file, "r")

        

open(existing_file, "w")

        

open(nonexisting_file, "r")

        

open(nonextising_file, "w")

        

open(existing_file, "a")

A.

Overwrite the file content.

B.

Create a new empty file.

C.

Raise an exception.

D.

Success.

E.

Append to the current content.

QUESTION 4

File all.txt has a list of names of all human beings on Earth who were alive at the moment of composing the file, one name per line. What is the worst method to read the content of this file?

.readline()

.readlines()

.read(n)

.read()

QUESTION 5

Alice wrote a program that reads the content of the file stuff.dat using method .read(200) in a "while" loop. The file size if 12567 bytes. The size of a character is 1 byte. How many characters are in the string returned by the last call to the method?

0

167

12567

63

All calls to the open() function return the same open file handle.

Several copies of the file are created, and each is open for reading.

The program crashes when it attempts to open the file for the second time.

Two or more open file handles are created.

Explanation / Answer

1) two or more open file handles are created.
2) A blank line

3) 1-D 2-A 3-C 4-B 5-E

4) readlines()