Question: When a Python program is reading a file, the data is input as plain ASCII characters in a string. What is the following code doing

When a Python program is reading a file, the data is input as plain ASCII characters in a string. What is the following code doing assuming a file is opened with file object inputFile?

r_in = inputFile.readline()

t = 0

while r_in != '':

r = r_in.rstrip(' ')

r_list = r.split('|')

n = float(r_list[2])

t += n r_in = inputFile.readline()

print(t)

The program is displaying the data from the file just as it was input without any changes.

Each line in file is in the format field1|filed2|number. The program is first putting the fields in a list and convert the last element to number form before adding it to a total.

The program is distributing the words from the file into three different lists.

The program is counting the occurrence of some words in the text input from the file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!