Editor

Student Grade Report

Beginner · Write the code · from Python For Loops: Iterate Over Anything with Examples

From the lesson: Python For Loops: Iterate Over Anything with Examples

Imagine you're a teacher with 30 students. You need to print a report card for each one. Would you write 30 separate print statements? Of course not. You'd tell the computer: "for each student, print their report card." That's exactly what a for loop does.

Read the lesson

Loop over the grades dictionary and print each student's name and their letter grade. A score of 90+ is "A", 80+ is "B", 70+ is "C", and below 70 is "F".

Expected output:

Alice: 95 (A)
Bob: 82 (B)
Charlie: 67 (F)
Diana: 73 (C)
grades = {"Alice": 95, "Bob": 82, "Charlie": 67, "Diana": 73}
# Loop over the dictionary and print each student's grade

More For Loops exercises

All Python exercises · 50 practice problems · Control Flow quiz