Testing and project · Lesson 25 of 25
Project: a grade report
Use everything you learned in a small real program.
10 minutes1 games
You have student marks in a dictionary. Write a program that prints each student's mark and grade, then the average and the top student. You'll use a dictionary, for, if, a function and f-strings.
Python
marks = {"Ali": 88, "Mona": 95, "Omar": 72, "Sara": 64}
def grade(m):
if m >= 85:
return "A"
elif m >= 70:
return "B"
return "C"
for name, m in marks.items():
print(f"{name}: {m} ({grade(m)})")
average = sum(marks.values()) / len(marks)
best = max(marks, key=marks.get)
print(f"Average: {average:.1f}")
print(f"Top student: {best}")Student scores
Validate data
Compute grades
Display report
Exercise
Print how many students passed (60 or more). The result is 3.
Expected output: 3
Python
marks = {"Ali": 88, "Mona": 95, "Omar": 52, "Sara": 64}
Learn more from
Played 0 of 1 games
Sign in to save your progress and earn XP.