Gradebook Report
Completed
Read n lines name score score .... Print a table: name left-aligned in 10 characters, average right-aligned in 6 with 1 decimal, and a grade (A ≥ 90, B ≥ 75, C ≥ 50, else F). Sort by average descending, then name. Finish with class average: X.
Input
Line 1: n. Then n lines.
Output
n + 1 lines.
Example
Input
3 ann 90 95 100 bob 70 80 cy 40 60 50
Output
ann 95.0 A bob 75.0 B cy 50.0 C class average: 73.3
Editor
Python
Hints
Collect (name, average) tuples, then sort them.
A loop over (limit, letter) pairs avoids repeated elifs.
Solution explanation
Separating the calculation (grade) from the presentation keeps the program readable.
Show solution
def grade(avg):
for limit, letter in ((90, "A"), (75, "B"), (50, "C")):
if avg >= limit:
return letter
return "F"
rows = []
for _ in range(int(input())):
name, *scores = input().split()
scores = list(map(int, scores))
rows.append((name, sum(scores) / len(scores)))
for name, avg in sorted(rows, key=lambda r: (-r[1], r[0])):
print(f"{name:<10}{avg:>6.1f} {grade(avg)}")
print(f"class average: {sum(a for _, a in rows) / len(rows):.1f}")