Ask Question
28 September, 07:21

Write a program to read a list of exam scores given as integer percentages in the range O to 100. Display the total number of grades and the number of grades in each letter-grade category as follows: 90 to 100 is an A, 80 to 89 is a B, 70 to 79 is a C, 60 to 69 is a D, and O to 59 is an F. Use a negative score as a sentinel value to indicate the end of the input. (The negative value is used only to end the loop, so do not use it in the calculations.) For example, if the input is

98 87 86 85 85 78 72 70 66 63 50 - 1

The output would be

Total number of grades = 14Number of A's = 1"Number of B's = 4Number of C's = 6Number of D'S

2Number of F's = 1

+5
Answers (1)
  1. 28 September, 07:31
    0
    def determineGrade (score) : if (score > = 90) : return "A" elif (score>=80) : return "B" elif (score>=70) : return "C" elif (score>=60) : return "D" else: return "F" totalGrade = 0 aCount = 0 bCount = 0 cCount = 0 dCount = 0 fCount = 0 user_score = int (input ("Enter your score: ")) while (user_score > 0) : totalGrade + = 1 grade = determineGrade (user_score) if (grade = = "A") : aCount + = 1 elif (grade = = "B") : bCount + = 1 elif (grade = = "C") : cCount + = 1 elif (grade = = "D") : dCount + = 1 else: fCount + = 1 user_score = int (input ("Enter your score: ")) print ("Total number of grades = " + str (totalGrade)) print ("Number of A's = " + str (aCount)) print ("Number of B's = " + str (bCount)) print ("Number of C's = " + str (cCount)) print ("Number of D's = " + str (dCount)) print ("Number of F's = " + str (fCount))

    Explanation:

    Firstly, we can define a function determineGrade () that takes one input values, score, and determine the grade based on the letter-grade category given in the question. (Line 1 - 11)

    Next, we declare a list of necessary variables to hold the value of total number of grades, and total number of each grade (Line 13 - 18). Let's initialize them to zero.

    Next, we prompt for user input of the first score (Line 20).

    To keep prompting input from user, we can create a while loop with condition if the current user_input is not negative, the Line 22 - Line 35 should keep running. Within the while loop, call the determineGrade () function by passing the current user_input as argument to obtain a grade and assign it to variable grade.

    We develop another if-else-if statements to track the number of occurrence for each grade (Line 26 - 35). Whenever a current grade meet one of the condition in if-else-if statements, one of the counter variables (aCount, bCount ...) will be incremented by one.

    By the end of the while-loop, we prompt use for the next input of score.

    At last, we display our output using print () function (Line 39 - 44).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program to read a list of exam scores given as integer percentages in the range O to 100. Display the total number of grades and ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers