Question
Average of Numbers (adapted from #6) Save the file as ch6_ex2.py Write a program that calculates the average of all the numbers stored in a
Average of Numbers (adapted from #6) Save the file as ch6_ex2.py
Write a program that calculates the average of all the numbers stored in a file. Test the program using the following text file (download from BlackBoard assignment page): 6-2-numbers.txt Your program must:
Open the hard-coded designated file for reading
Use a loop to read all lines from the file
Count the number of lines in the file
Keep a running total of all the numbers in the file
Display the total, the number of lines, and the average of all numbers.
All numeric displays must have two decimal points, and the decimal points should align in the column
Close the file
The output should look EXACTLY like the following:
Total: 564,479.00
# of Lines: 9
Average: 62,719.89
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started