Question: (number.txt) python please 25 18 7 4.2 99 103 100 Read Numbers Objectives: Practice file I/O. . Please download the file named numbers.txt to the
(number.txt)

python please
25 18 7 4.2 99 103 100 Read Numbers Objectives: Practice file I/O. . Please download the file named numbers.txt to the folder where your program is to reside. You are asked to write a program to read numbers from that file, count them and sum them. In the file, each line contains exactly one number. First of all, you want to open the file for reading. As long as end of file is not reached, your loop keeps reading numbers, one line at a time. Within the loop body, you accumulate the read-in number into a sum. Also you need to print to screen each number read from the file, one line per number. Finally, don't forget to close the connection to the file. Your program is expected to produce the following displays: 25.0 18.0 -7.0 4.2 99.0 103.0 -100.0 There were 7 numbers, totaling 142.2 end_of_file = False count = 0 total = 0 file Source = open('numbers.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 accumulate the line count W 3.2 accumulate the count of non-empty lines file Source.close() print ('There were', count, 'numbers, totaling', total )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
