Design a grade program that directs the user to enter information for one student. The user inputs the first name, last name, and three grades. The three grades MUST be entered into an array. Validate the grade input so that only grades between 0 and 100 are accepted. The program should display four output lines. One containing the student’s first and last name separated by a space One containing all three grades One containing the final average One containing the letter grade The program must calculate the final average. The letter grade is determined using the following ranges: A: 90-100 B: 80-89 C: 70-79 D: 60-69 F: Below 60

Respuesta :

Answer:

#section 1

f_name = input('Enter First Name: ')

l_name = input('Enter last Name: ')

age = int(input('Enter age: '))

grades = []

#section 2

while True:

   try:

       g1 = int(input('Enter First Grade: '))

       if (-1 < g1 < 101):

           g2 = int(input('Enter Second Grade: '))

           if (-1 < g2 < 101):

               g3 = int(input('Enter Third Grade: '))

               if (-1 < g3 < 101):

                   break

               else:

                   raise

           else:

               raise

       else:

           raise

   except:

       print('Grades must be within the range 0 and 100 ')

#section 3  

grades.append(g1)

grades.append(g2)

grades.append(g3)      

average = round(sum(grades)/len(grades), 2)

def lettergrade(a):

   letter = 'A'

   if a < 60:

       letter = 'F'

   elif 61 < a < 70:

       letter = 'D'

   elif 69 < a < 80:

       letter = 'C'

   elif 81 < a < 90:

       letter = 'B'

   elif 91 < a < 101:

       letter = 'A'

       

   return letter

#section 4

print('\n ---------Result-------------\n\n')

print('{} {}'.format(f_name, l_name))

print(grades)

print(average)

print(lettergrade(average))

Explanation:

The programming language used is python.

#section 1

In this section the program prompts the user to enter its first name last, last name and age. An empty list is also created to hold the grades of the student.

#section 2

The program uses a WHILE loop, TRY and EXCEPT block with IF statements to check if the grades are within range, if the grades are out of range an error is raised and the except block tells the user that a wrong input has been entered, the while loop keeps running until it has collected values that are within the stipulated range before it breaks.

#section 3

In this section, all the scores collected appended to the grades list and the average is calculated.

A function is also created, that would evaluate the letter grade depending on the value that is passed to it.

#section 4

The results are printed to the screen

Ver imagen jehonor