Loading lessons...
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
- Run the starter and enter a few scores.
- Compute
average = sum(scores) / len(scores). - Print
min(scores)andmax(scores). - Guard against dividing by zero if no scores were entered.
- 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.