In: Computer Science
A teacher has five students who have taken four tests. The teacher uses the following
grading scale to assign a letter grade to a student, based on the average of his or her four
test scores.
--------------------------------------------------------------------
Test Score Letter Grade
--------------------------------------------------------------------
90 – 100 A
>= 80 < 90 B
>= 70 < 80 C
>= 60 < 70 D
< 60 F
-------------------------------------------------------------------
Write a program that uses Python List of strings to hold the five student names, a Python
List of five characters to hold the five students’ letter grades, and a Python List of four
floats to hold each student’s set of test scores.
The program should allow the user to enter each student’s name and his or her four test
scores. It should then calculate and display each student’s average test score and a letter
grade based on the average. Input Validation: Do not accept test scores less than 0 or
greater than 100.
please use comments to describe your work.
names=[]
averages=[]
grades=[]
for i in range(5):
name = input('Enter student name: ')#get name
names.append(name)#add to array
scores=[]
for j in range(4):
score = float(input("Enter {}'s test score {}:
".format(name,j+1)))#get score
while score<0 or score>100:#if invalid score, keep asking
again
score = float(input("Invalid!!\nEnter {}'s test score {}:
".format(name,j+1)))
scores.append(score)#add score to the array for holding all 4
scores
averages.append(sum(scores)/4)#after getting score, calculate
average and add to averages
#determine grade
if averages[-1]>=90:
grades.append('A')
elif averages[-1]>=80:
grades.append('B')
elif averages[-1]>=70:
grades.append('C')
elif averages[-1]>=60:
grades.append('D')
else:
grades.append('F')
#print details
print('{:30s}{:10s}{:10s}'.format('Name','Average','Grade'))
for i in range(5):
print('{:30s}{:<10g}{:10s}'.format(names[i],averages[i],grades[i]))