Lesson 68 +35 XP

Project 4: Grade Calculator with Lists

Project 4: Grade Calculator with Lists

Collect a list of scores and print the average, highest, and lowest.

The goal

Keep typing scores until the user enters -1, then show the average, min, and max.

What you practice

  • Lists and append()
  • while loops
  • sum(), min(), max()
  • len()

Starter code

scores = []

while True:
    value = input("Enter a score (-1 to stop): ")
    if value == "-1":
        break
    scores.append(int(value))

print("You entered", len(scores), "scores")

Step-by-step

  1. Run the starter and enter a few scores.
  2. Compute average = sum(scores) / len(scores).
  3. Print min(scores) and max(scores).
  4. Guard against dividing by zero if no scores were entered.
  5. Wrap the int conversion in a try/except.

Checklist

  • [ ] Scores are stored in a list
  • [ ] -1 stops the loop
  • [ ] The average is a float
  • [ ] Min and max are shown
  • [ ] An empty list doesn't crash
  • [ ] Bad input is handled

TL;DR

  • append() grows the list.
  • sum(), min(), max() summarize it.
  • Guard division when the list is empty.