In: Computer Science
Create a grade report.
The grades will be stored as a list of tuples:
[ (grade_percentile_1 , grade_letter_1) , (grade_percentile_2 , grade_letter_2) , .... ]
Create each grade percentile using a random generator to uniformly choose a percent between 50% and
100%. Assign the letter grade based on the chosen percentile using the table below.
Numeric Average | Letter Grade | Numeric Average | Letter Grade |
93 - 100 | A | 90 - 92.99 | A- |
87 - 89.99 | B+ | 83 - 86.99 | B |
80 - 82.99 | B- | 77 - 79.99 | C+ |
73 - 76.99 | C | 70 - 72.99 | C- |
67 - 69.99 | D+ | 63 - 66.99 | D |
60 - 62.99 | D- | Below 60 | F |
Create 35 random grades and store them as a list of 35 tuples. You decide on the class name. Then print all 35 grades to the screen, along with summary information (total number of grades, minimum grade, maximum grade, and average grade). Show all grades and the average with exactly 2 decimal places.
Submit your program script called grades.py. Use functions as appropriate for optimal abstraction and encapsulation.
Here is an example of how the grade report could appear:
Grades for Applied Neural Networks Letter Grade Numeric Grade (%) 86.75 B+ 76.62 C+ 85.50 B 74.00 C 92.35 A- 97.72 A 55.35 F 72.67 C 65.87 D 94.87 A 97.53 A 63.42 D 82.57 B 72.43 C- 87.65 B+ 68.56 D+ 59.34 F 62.87 D 92.62 A Total Grades: 19 Minimum Grade: 55.35 Maximum Grade: 97.72 Average Grade: 78.35 |
Hi
Program:
import random
def assign_letter_grade(score):
if score <= 100 and score >=93: return "A"
elif score <= 92.99 and score >=90: return "A-"
elif score <= 89.99 and score >= 87: return "B+"
elif score <= 86.99 and score >=83: return "B"
elif score <= 82.99 and score >=80: return "B-"
elif score <= 79.99 and score >=77: return "C+"
elif score <= 76.99 and score >=73: return "C"
elif score <= 72.99 and score >=70: return "C-"
elif score <= 69.99 and score >=67: return "D+"
elif score <= 66.99 and score >=63: return "D"
elif score <= 62.99 and score >=60: return "D-"
else : return "F"
List = []
y=0
max=0
min=0
total=0
for x in range(35):
score = random.uniform(50,100)
if(score > max):
max=score
if(x == 0):
min=score
elif(score < min):
min=score
total=total+score
t1 = (score, assign_letter_grade(score))
List.insert(x, t1)
y=y+1
print("Grades for Applied Neural Networks")
print("Numeric Grade (%) Letter Grade")
for k in List:
#print(k)
print("%.2f %s" % (k[0], k[1]))
print("Toal Grades: %d" % y)
print("Minimum Grade: %.2f" % min)
print("Maximum Grade: %.2f" % max)
avg = total/y
print("Average Grade: %.2f" % avg)
Screenshot: