(Assign grades) Write a program that reads a list of scores and then assigns grades based on the following scheme:
The grade is A if score is >= best – 10.
The grade is B if score is >= best – 10. .
The grade is C if score is >= best – 30.
The grade is D if score is >= best – 40.
The grade is F otherwise.
Here is a sample run:
Enter scores: 40 55 70 58
Student 0 score is 40 and grade is C
Student 1 score i s 55 and grade is B
Student 2 score is 70 and grade is A
Student 3 score is 58 and grade is B
#Prompt the user to enter the scores of total number of students
scores = list(map(int,input('Enter all the scores ').strip().split()))
grades = list()
#Method getGrade assigns grades based on grading scheme
def getGrades(scores,grades):
best = max(scores)
for i in range(len(scores)):
if (scores[i] >= best-10):
grades.append('A')
elif (scores[i] >= best-20):
grades.append('B')
elif (scores[i] >= best-30):
grades.append('C')
elif (scores[i] >= best-40):
grades.append('D')
else:
grades.append('F')
#Get grades
getGrades(scores, grades)
#Display results
for i in range (len(scores)):
print("Student {0} score is {1} and grade is {2}".format(i,scores[i],grades[i]))
Output:
Enter all the scores 40 55 70 58
Student 0 score is 40 and grade is C
Student 1 score is 55 and grade is B
Student 2 score is 70 and grade is A
Student 3 score is 58 and grade is B