In: Computer Science
This exercise is a bit more complicated and will be a review of what we’ve learned about lists and dictionaries. The aim of this exercise is to make a gradebook for a group of students.
Follow these steps:
students = {
"lloyd": {
"name": "Lloyd",
"homework": [90.0,97.0,75.0,92.0],
"quizzes": [88.0,40.0,94.0],
"tests": [75.0,90.0]
},
"alice": {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
},
"tyler": {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}
}
A – 100% - 90%
B – 90% - 80%
C – 80% - 70%
D – 70% - 60%
F – 59% - below
Your program should work for any list of students, i.e. your solution should be general in that it takes in any dictionary in this format of any length, process the data, and return the results. You should test it with this input, as well as input you make up. I will also test it with both this input as well as another set of data that is formatted similarly.
Code:-
for name,dic in students.items():
print("name:- "+name)
print("homework scores:-",end=" ")
print(students[name]["homework"])
print("quiz scores:-",end=" ")
print(students[name]["quizzes"])
print("test scores:-",end=" ")
print(students[name]["tests"])
hw_score_total=0
quiz_score_total=0
test_score_total=0
for i in students[name]["homework"]:
hw_score_total +=i
for j in students[name]["quizzes"]:
quiz_score_total +=j
for k in students[name]["tests"]:
test_score_total +=k
print("average homework scores:-",hw_score_total/len(students[name]["homework"]))
print("average quiz scores:-",quiz_score_total/len(students[name]["quizzes"]))
print("average test scores:-",test_score_total/len(students[name]["tests"]))
grade=''
percent = ((hw_score_total+quiz_score_total+test_score_total)*100/((len(students[name]["homework"]) + len(students[name]["quizzes"]) + len(students[name]["tests"]))*100))
if(percent >=90 and percent<=100):
grade = 'A'
elif(percent >=80 and percent<90):
grade = 'B'
elif(percent >=70 and percent<80):
grade = 'C'
elif(percent >=60 and percent<70):
grade = 'D'
else:
grade = 'F'
print("letter grade:- ",grade)
print(" ")
Screenshots have been added for additional clarity