9.10 Quiz5 Write a function named calculate scores that takes two parameters, an input file name and an output file name. The input file has
9.10 Quiz5
Write a function named calculatescores that takes two parameters, an input file name and an output file name. The input file has only one column of scores. The function calculatescores will read in the scores from the file and write their count, total, and average into the output file. Your program should prompt the user to enter an input and an output filename. Here is a sample run:
Please enter the input file name: scores.txt Please enter the output file name: scores.out
The scores.txt has unspecified number of scores and extra blank lines in the file:
100 90.5 95 <-- blank line 80.2 40.5 <-- blank line <-- blank line <-- more scores
After you calculate the number of scores, total, and average from the input file, write the results to the output file using the string format. Remember, dont count the blank lines in the input file. Your output file should look like the following:
There are 5 scores The total is 406.20 The average is 81.24
You will use the main level script section to separate your input statements and function call from the function definition. Use string format to format the total and average to two decimal places. Your program should work for any input file and not just the one as shown here. I will test your program with a different file.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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