Question: Write a function named calculate_scores that takes two parameters, an input file name and an output file name . The input file has only one
Write a function named calculate_scores
that
takes two parameters, an input file
name
and an
output file
name
.
The input file
has only one column of scores.
The function calculate_scores
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 a 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 t
he output
file
using
the
string format
. Remember, dont count the blank lines in the input file.
You
r 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 s
tatement
s
and function call
from the function definition.
Use string format to format the
total and average to two decimal
places.
Rubric:
Function syntax
-
2
Parameters
-
2
file
open (read/write)
8
file write
-
6
file close
-
4
incorrect
calculation (total, number of scores
, average)
-
12
format string
-
2
main level script section
-
2
call function
-
2
If statement
-
4
for statement
-
4
Total: 4
8
points.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
