Write a program to calculate student's average test scores and the grade. You may assume the following input data:
Jack Johnson 85 83 77 91 76
Lisa Aniston 80 90 95 93 48
Andy Cooper 78 81 11 90 73
Ravi Gupta 92 83 30 69 87
Bonny Blair 23 45 96 38 59
Danny Clark 60 85 45 39 67
Samantha Kennedy 77 31 52 74 83
Rabin Bronson 93 94 89 77 97
Sheila Sunny 79 85 28 93 82
Kiran Smith 85 72 49 75 63

Respuesta :

Answer:

def gradeAverage():

   grades = []

   i = 0

   while i < 5:

       a = int(input('enter score ' + str(i + 1) + ': '))

       grades.append(a)

       i = i+1

   #print(grades)

   average = sum(grades)/len(grades)

   #print(average)

   return average

def lettergrade(a):

   letter = 'A'

   if a < 60:

       letter = 'F'

   elif 59 < a < 63:

       letter = 'D-'

   elif 62 < a < 67:

       letter = 'D'

   elif 66 < a < 70:

       letter = 'D+'

   elif 69 < a < 73:

       letter = 'C-'

   elif 72 < a < 77:

       letter = 'C'

   elif 76 < a < 80:

       letter = 'C+'

   elif 79 < a < 83:

       letter = 'B-'

   elif 82 < a < 87:

       letter = 'B'

   elif 86 < a < 90:

       letter = 'B+'

   elif 89 < a < 94:

       letter = 'A-'

   elif 93 < a < 101:

       letter = 'A'

   return letter

numOfStudents = int(input('How many students: '))

names = []

aver = []

grade =[]

while numOfStudents > 0:

   studentName = input('Enter students name: ')

   names.append(studentName)

   a = gradeAverage()

   aver.append(a)

   grade.append(lettergrade(a))

   numOfStudents = numOfStudents - 1

for name in names:

       for score in aver:

           for letter in grade:

               if names.index(name) == aver.index(score) == grade.index(letter):

                   print('%s : Average =  %d  Letter Grade:  %s \n' %(name, score, letter))

                   break

Explanation:

The programming language used is python.

Two functions were created, the first function gradeAverage() was used to calculate the average values of the scores.

The second function lettergrade(a) was used to get the letter grade i.e(A, A-, C, D, e.t.c.) and it takes its argument from the average.

The main block of code asks for how many students are there and prompts the user to input their names and scores for all the students.

It takes that data calculates the average and the letter grade and prints out the names of the students, their average and their letter grade.

Ver imagen jehonor