I'm studying counting and sorting. I have a problem with this task:
Some people participate in math competition. Winner is a person with the biggest amount of points reached (winners are distributed for each grade). Find the value of max points reached for each grade. In each grade takes part one person or more
INPUT
Information about all participants in a file ('input.txt', for example) where each line is supposed to have this structure:
family_name name grade result
Family name and name should be written as a string, grades are in range 10 to 12, results (points) are in range 0 to 100.
OUTPUT
Print three numbers: points of each winner of 10th, 11th and 12th grades. Inner file is supposed to be written in this way:
open('input.txt', 'r', encoding='utf8')
I have already solved this task but I didn't use counting sorting. Here is full code
def listAverage(list):
sum = 0
for i in list:
sum += i
return sum / len(list)
classes = []
inFile = open('input.txt', 'r', encoding='utf-8')
for line in inFile:
grade, mark = line.split()[2:]
if grade in classes:
classes[grade].append(int(mark))
else:
classes[grade] = [int(mark)]
for i in range(10, 13):
print(listAverage(classes[str(i)]), end=' ')