Start learning free

LESSON 173 OF 410 · PROJECTS: EVERYDAY PROGRAMS

Report Card V4 - Multiple Students in Python

Practice

Combine lists, loops, and conditionals to print a letter grade for each student in a class.

You start with:

names = ["Alice", "Bob", "Carol", "Dan"]
scores = [92, 78, 85, 67]

Build:

Alice: A
Bob: C
Carol: B
Dan: D

Rules:

  • Loop over the indices of the students (range(len(names))) so you can read the name and the score at the same position.
  • Use the same scale as V3: 90+ A, 80-89 B, 70-79 C, 60-69 D, below 60 F.
  • On each iteration print the name, a colon and a space, then the grade, for example Alice: A.

Inside for i in range(len(names)):, read scores[i] and apply the V3 grading chain.

names = ["Alice", "Bob", "Carol", "Dan"]
scores = [92, 78, 85, 67]

for i in range(len(names)):
    score = scores[i]
    if score >= 90:
        grade = "A"
    elif score >= 80:
        grade = "B"
    elif score >= 70:
        grade = "C"
    elif score >= 60:
        grade = "D"
    else:
        grade = "F"
    print(names[i] + ": " + grade)

STEP 1 OF 8
    Ctrl + Enter to check

    Report Card V4 in Python

    Keep going with PythonAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free