Checkpoint 6.13.1.
Write code that iterates through the given list "scores" and checks which letter grade each score has earned. In response, it should add the corresponding letter grade to the empty list "grades", according to the table below.
Score | Grade |
---|---|
>= 90 | A |
[80-90) | B |
[70-80) | C |
[60-70) | D |
< 60 | F |
The square and round brackets denote closed and open intervals. A closed interval includes the number, and open interval excludes it. So 79.99999 gets grade C , but 80 gets grade B.
Solution.
scores = [77.51, 92.86, 98.01, 69.71, 78.52, 59.69, 60.49, 85.04, 87.33, 91.04]
grades = []
for fl_sc in scores:
if fl_sc < 60:
gr = "F"
grades.append(gr)
elif fl_sc < 70:
gr = "D"
grades.append(gr)
elif fl_sc < 80:
gr = "C"
grades.append(gr)
elif fl_sc < 90:
gr = "B"
grades.append(gr)
else:
gr = "A"
grades.append(gr)