Add a function to determine the letter grade (\'A\', \'B\', \'C\', \'D\'; or \'F
ID: 3929794 • Letter: A
Question
Add a function to determine the letter grade ('A', 'B', 'C', 'D'; or 'F') of one exam score. Create and use named constants for each of the point cutoffs (90 for an A, 80 for a B, 72 for a C, 62 for a D). Refer to the top four lines of the sample output below. Display the letter grade (inside parentheses) next to each score by calling your new function for each exam score. Add a function to determine the largest of the three exam scores. Refer to the bottom line of the sample output below. Display the highest score below the other results. Test your project and check your results. Show your project output and code. Sample output: Student Name: Cindy Exam #1: 90 (A) Exam #2: 98 (A) Exam #3: 85 (B) Highest score: 98 data: Amy 90 98 85 Melanie 80 89 90 Bob 62 55 76 Timothy 80 79 72Explanation / Answer
dict = {90:"A",80:"B",72:"C",62:"D"}
def get_max(list):
return max(list)
def grade(score):
for i in dict:
if(score>=i):
return dict[i]
file = open("scores.txt","r")
data = file.read().split(" ")
for line in data:
stud = line.split(" ")
scores = map(int,stud[1:])
print "Student Name:"+stud[0]
print "Exam #1:",scores[0],grade(scores[0])
print "Exam #2:",scores[1],grade(scores[1])
print "Exam #3:",scores[2],grade(scores[2])
print "Highest score:",get_max(scores)
"""
sample output
Student Name:Amy
Exam #1: 90 B
Exam #2: 98 B
Exam #3: 85 B
Highest score: 98
Student Name:Melanie
Exam #1: 80 B
Exam #2: 89 B
Exam #3: 90 B
Highest score: 90
Student Name:Bob
Exam #1: 62 D
Exam #2: 55 None
Exam #3: 76 C
Highest score: 76
Student Name:Timothy
Exam #1: 80 B
Exam #2: 79 C
Exam #3: 72 C
Highest score: 80
"""
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.