Write a program that calculate the average of all the number


Problem

Write a program that calculates the average of all the numbers stored in a file. Test the program using the following text file 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

Exceptions offer a gracious way to exit a program when things go wrong. Modify the program you wrote for exercise 2 to handle the exceptions (See 6.4 Exceptions on page 341). Test the program using the following text
6-3-lines1.txt
6-3-lines2.txt

Your program must:

• Include a try block in the main function that holds most of the code from exercise 2.

• The try block must handle any: o IOError exceptions are raised when an attempt is made to open the file. o ValueError exceptions are raised when the items read from the file cannot be converted to type float.

• Include all requirements outlined in "your program must" from #2.

• When you turn in ch6_ex3.py it should be set to read 6-3-lines2.txt.

It will not pass CodeGrade if it is set to read 6-3-lines1.txt
For the file 6-3-lines1.txt,
the output should look like the following:
Total: 227,595.00
# of Lines: 9.00
Average: 25,288.33

For the file 6-3-lines2.txt, the output should look like the following:

Non-numeric data is found in the file.

If you try to load a file name that does not exist, the output should look like the following:

An error occurred while trying to read the file.

Try loading the same files in the code from exercise #2, recreate the same mistakes, and compare how exception handling makes for a more user-friendly experience

Request for Solution File

Ask an Expert for Answer!!
Python Programming: Write a program that calculate the average of all the number
Reference No:- TGS03323563

Expected delivery within 24 Hours