In this programming problem, given the scores of five different subjects for k
different students, you are required to write a function named average
that returns a list of the average score for each subject.
You can start with this template code and ensure your code can run correctly within this template:
from statistics import mean # you may use this function to find the average of a list of number
def average(scores):
# your code here
# Note that the following code is for local testing purposes only. You should leave this part of code unchanged and not submit it to the OJ system.
T = int(input())
for t in range(T):
k = int(input())
scores = [map(int, input().split()) for _ in range(k)]
avers = average(scores)
for m in avers:
print(f'{m:.2f}', end=' ')
print()
Please note that you only have to submit the definition of the average
function to the OJ system along with the import statement if you used the module. The rest of the code is for your local testing purposes only.
Input Specification
The first line of the input gives the number of test cases, , and then test cases follow.
For each test case, it will consist of lines. The first line consists of a number , which represents the number of students. After that, lines follow. Each line contains 5 integers, indicating the scores for five different subjects.
Constraints
Output Specification
For each test case, output a single line containing 5 numbers indicate the average score for five different subjects respectively.
Sample Input
1
3
90 80 70 60 50
50 60 70 80 90
80 80 80 80 80
Sample Output
73.33 73.33 73.33 73.33 73.33
Explanation
The 1
on the first line means one test cases follow.
The 3
on the second line means three are 3 students ( = 3 ).
For the third line, it represents the first student got 90
on , 80
on , and so on.
For the fourth line, it represents the second student got 50
on , 60
on , and so on.
For the fifth line, it represents the third student got 80
on , 80
on , and so on.
So the output of this test case should be 73.33 73.33 73.33 73.33 73.33
which represent five average scores of five different subjects.
Hint
zip
mean
Comments