Python program: Write the following functions to process the content read from t
ID: 3744321 • Letter: P
Question
Python program:
Write the following functions to process the content read from the file.
a. Class average
b. Pass rate (total number of students who passed divided by the total number of students)
c. Highest score and Lowest Score
d. Count of A grades (above 90%), B grades (above 80%), C grades (above 60%), D grades (above 50%), and F grades (below 50%)
And then test each of the above functions. Display all the results from the function calls where each student’s grades are printed and also the class report is printed. Sample input file content:
scores.txt
Naji Hasan 90 85 87
Lisa Smith 80 67 70
Andy Malik 75 80 52
Ravi Gupta 90 95 98
Dave Blair 50 61 70
Sara Clark 70 65 81
Sami Moosa 55 50 71
Imed Radhi 90 83 89
Kira Sunny 65 70 69
Hind Ahmed 70 81 88
Explanation / Answer
def class_average(scores): total = 0 count = 0 for student in scores: for i in range(1, len(student)): total += student[i] count += 1 return total / count def count_grades(scores): a, b, c, d, f = 0, 0, 0, 0, 0 for student in scores: average = 0 for i in range(1, len(student)): average += student[i] average /= len(student)-1 if average >= 90: a += 1 elif average >= 80: b += 1 elif average >= 60: c += 1 elif average >= 50: d += 1 else: f += 1 return a, b, c, d, f def pass_rate(scores): a, b, c, d, f = count_grades(scores) return (a+b+c+d) / len(scores) def highest_and_lowest(scores): highest = 0 lowest = 100 for student in scores: for i in range(1, len(student)): if student[i] > highest: highest = student[i] if student[i]Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.