Respuesta :
Answer:
- 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).