Question: (word.txt) Python Please 1. 2. 3. 4. 5. 6. 7. 8. 9. apple banana kiwi elephant aquamarine anteater violet orange indigo 10. purple umber 11.

(word.txt) Python Please 1. 2. 3. 4. 5. 6. 7. 8. 9.(word.txt)

apple banana kiwi elephant aquamarine anteater violet orange indigo 10. purple umber

11. Please download the file named words.txt to the folder where your

Python Please

1. 2. 3. 4. 5. 6. 7. 8. 9. apple banana kiwi elephant aquamarine anteater violet orange indigo 10. purple umber 11. Please download the file named words.txt to the folder where your program is to reside. You are asked to write a program to read lines from a file and count those that are not blank. First of all, you want to open the file for reading. As long as end of file is not reached, your loop keeps reading each line. You are advised to use two counter variables to keep track of the number of lines and the number of non-blank lines. Within the loop body, you need to determine whether the read line is a non-blank line. Finally, don't forget to close the connection to the file. Your program is expected to produce the following displays: This file has 11 non-blank lines out of a total of 14 lines end_of_file = False numLines = 0 numNonEmptyLines = 0 fileWords = open('words.txt', 'r') # as long as end of file is not reached, we keep reading one line at a timewhile not end_of_file: # TODO: # 1. read one line from file # 2. if this is an end-of-file line, turn on the flag end_of_file # 3. otherwise # 3.1 determine whether it is a non-empty line # 3.2 if non-empty line, increment numNonEmptyLines by one # 3.3 increment numLines by one fileWords.close() print ('This file had', numNonEmptyLines, 'non-empty lines out of a total of', numLines, 'lines')

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!