CSV Files
Completed
Read n lines name,score and write them to scores.csv with a header row using csv.writer. Then read it with csv.DictReader and print the name with the highest score and the average score with 1 decimal.
Input
Line 1: n. Then n lines name,score.
Output
Two lines.
Example
Input
3 ann,88 bob,95 cy,70
Output
bob 84.3
Editor
Python
Hints
csv.writer(f).writerow(list) writes one row.
csv.DictReader gives each row as a dict keyed by the header.
Solution explanation
The csv module handles quoting and commas inside values correctly - don't split CSV by hand in real code.
Show solution
import csv
n = int(input())
with open("scores.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["name", "score"])
for _ in range(n):
writer.writerow(input().split(","))
with open("scores.csv", newline="") as f:
rows = list(csv.DictReader(f))
best = max(rows, key=lambda r: int(r["score"]))
print(best["name"])
print(f"{sum(int(r['score']) for r in rows) / len(rows):.1f}")