7— File Data Statistics
In this project, you will write a program to read a series of values from a file and calculate the following statistics:
• A count of the number of values read from the file
• The sum (total) of the values read from the file
• The average (total / count) of the values read from the file
• The largest number read from the file
• The smallest number read from the file
Example of program in operation:
Reading data from file...
Read complete!
Count: 10
Total: 786
Average: 78.6
Highest: 100
Lowest: 48
Development Process
A template for this project is provided with comments to help guide you as you write the program to accomplish the following steps:
1. Download both the template and data file for Program 7 and save them to the same folder on your computer/flash drive.
2. View/print the following programs from the Chapter 8 and Chapter 10 course modules in Blackboard as examples to follow as you complete this program:
a. Program 10-6 – open file in read mode; read data; add to total
b. Program 8-11 – finding the highest (max) value
c. Program 8-12 – finding the lowest (min) value
3. Open the template. Below the Step 1 comment, write a line of code to open the “Prog7Data.txt” file in read mode. The variable name on the left side of the equal sign is the file’s internal name and will be used in the rest of your code when referencing the file. For example, in Program 10-6 the file is opened and given the internal name videoFile.
4. Below the Step 2 comment, write a line of code to read the first line from the file and to store the string into a variable.
5. Below the Step 3 comment, write the first line of a while loop to test if the end of the file has been reached. Remember in Python that a null string (“”) indicates the end of the file. The code for Steps 4-9 will be indented under the while loop.
6. Below the Step 4 comment (note the indentation), write a line of code to convert the string value stored in the variable to a float value, then store the result back into the same variable.
7. Below the Step 5 comment (note the indentation), write a line of code to add the float value from the variable in Step 4 to the variable named total and store the result back into total (i.e. this is a running total/accumulator).
8. Below the Step 6 comment (note the indentation), write a line of code to add 1 to the count accumulator variable. This variable simply adds 1 to count for each line read from the file.
9. Below the Step 7 comment (note the indentation), write an if statement to test if the float value in the variable from Step 4 is the new “low” value. See Program 8-12 for an example of this logic.
10. Below the Step 8 comment (note the indentation), write an if statement to test if the float value I the variable from Step 4 is the new “high” value. See Program 8-11 for an example of this logic.
11. Below the Step 9 comment (note the indentation), write a line of code to read the next line from the file and to store the string into a variable. NOTE: This should look the same as the code from Step 2, but will be indented under the loop.
12. Below the Step 10 comment (not indented), write a line of code to close the file.
13. Below the Step 11 comment, write a series of print statements to display the count, total, average, highest and lowest.
count = 0
total = 0
highest = -1000
lowest = 1000
print("Reading data from file...")
while
#STEP #4 - Convert the value read from the file to a float
#STEP #5 - Add the value to the running total
#STEP #6 - Add 1 to the counter
#STEP #7 - Check for new low value
#STEP #8 - Check for new high value
#STEP #9 - Read the next line from the input file
and this is the data
76
82
29
29
33
57
91
55
36
35
13
32
40
80
75
94
11
57
75
19
I HAVE NO IDEA WHERE TO EVEN START!!! Someone please help me :(