In: Computer Science
This program will determine the letter grade for a student. It will ask for scores (could be labs, activities, quizzes, or projects) and then display some basic statistics derived from the scores.
In Python, Write a program that continuously asks for a non-negative score until the user enters -1. IF the user enters a valid score ask for the possible score for that assignment, we will not assume all scores will have the same maximum value. We will assume that no one will receive a score of 0 on any assignment IF anything it is actually turned in, meaning a score of 0 indicates that the score was not turned it. It’s still the score for the assignment, but this fact will be used later in the assignment. Once all of the scores have been entered display the following information:
• Total number of scores entered. • Total points for the student. • Total number of possible points • Class percentage, with 2 decimal place. • Letter grade using the 90, 80, 70, 60 grading scale. • If we believe the student has dropped. We will assume this is true if ALL of the entered scores are 0 (indicating that nothing was turned it). • If all of the scores were turned in or if the student is missing at least one score
'''Code to generate letter grade for a student and to display statistical details.'''
scores = [] #Store scores obtained
possible_scores=[] #Store possible scores
while(True): #Repeat till the user enter -1
score = int(input("Enter score: ")) #user score
if score<-1: #Check non-negative number and display appropriate message
print("Enter non-negative score")
continue
elif score == -1: #Check -1 and stop
break
possible_score = int(input("Enter possible score: ")) #User possible score
scores.append(score) #Append all the score
possible_scores.append(possible_score) #Append all the possible score
percentage = (sum(scores)/sum(possible_scores))*100 #Percentage is the total score obtain divided by the maximun score * 100
'''Letter grade using the 90, 80, 70, 60 grading scale . Check the grade .
percentage Grade
100-90 A
90-80 B
80-70 C
70-60 D
60-0 F(Fail)'''
if percentage > 90:
grade = 'A'
elif percentage > 80:
grade ='B'
elif percentage >70:
grade = 'C'
elif percentage > 60:
grade = 'D'
else:
grade = 'F'
'''Display the statistical details'''
print("Total number of scores entered:", len(scores))#Total number of scores entered
print("Total points for the student: ",sum(scores)) #Total points for the student
print("Total number of possible points: ",sum(possible_scores)) #Total possible points
print("Percentage:{:.2f}".format( percentage)) #Percentage obtained
print("Student Grade : ", grade) #Grade received
'''Check if all the scores are zero then the student dropped.'''
if all(v == 0 for v in scores):
print("Student has dropped")
Summary:
Calculate the letter grade and to dislplay the statistical details based on the scores provided
Input: Student scores and possible scores
Step1: Get input from the user till the score is -1. 1) Check if the score is not negative ; If is negative display error message 2) Check if the score is -1 ; If -1 stop user input 3) Append the score to the list of scores and possible scores.
Step 2: Find total of scores and possible scores usinf sum() and total number of scores using len() . Calculate percentage : Percentage is given by the total sum of marks obtained divided by total possible mark and the ans multiplied by 100.
percentage = (Total Sum of Scores obtained/Total Marks Possible)*100
Step 3: Letter grade using the 90, 80, 70, 60 grading scale . Check the grade using if- elif statement .
Percentage Grade
100-90 A
90-80 B
80-70 C
70-60 D
60-0 F(Fail)
Step 4: If all the scores in the score obtained are zero then "The Student has dropped". all() checks all the values if any one is False if return False.