#C14299. Student Average Score Calculator
Student Average Score Calculator
Student Average Score Calculator
You are given a CSV formatted input from standard input. The first line is the header with exactly four columns: name
, math
, science
, and english
. Each subsequent line contains a student's name and their scores in these subjects. Some scores may be missing (i.e., empty). Your task is to calculate the average score for each student using the formula:
$ average = \frac{\text{sum of available scores}}{\text{number of available scores}} $
Round the average to exactly two decimal places. Then, output a CSV to standard output with two columns: name
and average_score
, where the first line is the header. If a student has no valid scores, you may output N/A
for that student.
inputFormat
The input is given via standard input and consists of multiple lines in CSV format. The first line is the header: "name,math,science,english". Each following line contains the student's name and their corresponding scores. Each field is separated by a comma. Missing scores will be indicated by an empty field.
outputFormat
Print the result to standard output in CSV format. The first line should be the header: "name,average_score". For each student, output the name and his/her average score (rounded to two decimal places), separated by a comma.
## samplename,math,science,english
Alice,85,90,88
Bob,78,84,79
Charlie,,75,85
name,average_score
Alice,87.67
Bob,80.33
Charlie,80.00
</p>