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...
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.
Template for Program 7
Complete the code as discussed in the Program 7 Instructions
Accumulators to hold count and running total
count = 0
total = 0
Variables to hold the current highest and lowest values
highest = -1000
lowest = 1000
STEP 1 - Open the data file named prog7Data.txt in read mode
Print a message to let the user know what is happening
print("Reading data from file...")
STEP 2 - Read the first line from the file to get things started
STEP 3 - Use a while loop to test if the end of file has been reached
#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
STEP #10 - Close the file
STEP #11 - Print the summary statistics (count, total, average, etc.)
and this is the data
I HAVE NO IDEA WHERE TO EVEN START!!! Someone please help me :(