In: Computer Science
This is an assignment for python.
Download the code “
GradeBook.py
”
You will be modifying the code to do the following:
1)
create an empty dictionary named “FinalAverages”
2) In one for loop you will zip all lists together and get their individual members on each iteration. You can name
these what ever you want.
3) on each iteration: Calculate the WEIGHTED average using the weights provided, and then add a new dictionary
value to the dictionary “
FinalAverages
”. The KEY for this dictionary will be the name on this iteration, and the
VALUE will be the average of the student.
4)
the whole
dictionary,
and
then
ONLY ”Jack”
5) BONUS: if you create a function that takes an input of the 4 lists, and an output of the appropriate dictionary:
adding 1 point. Your code must then use this function to create the appropriate dictionary, apply the weights
(Store them in that function), and then output the
values you got.
Gradebook.py is:
Students = ['Bill', 'Sue', 'Janet', 'Cindy', 'Ray', 'Jack', 'Barbra', 'Matt', 'Joey', 'Adam', 'Becky', 'Mona'] Exam1 = [100, 80, 26, 45, 89, 65, 92, 75, 76, 15, 80, 50] Exam2 = [88, 95, 55, 60, 81, 25, 70, 100, 95, 70, 72, 10] Exam3 = [65, 92, 100, 80, 26, 92, 55, 60, 80, 55, 60, 75] scaleExamOne = 0.3 scaleExamTwo = 0.3 scaleExamThree = 0.4
Python code:
def
waverage(students,exam1,exam2,exam3,scaleExamOne,scaleExamTwo,scaleExamThree):
result = {}
for i in range(len(students)):
wavg = (exam1[i]*0.3) + (exam2[i]*0.3) + (exam3[i]*0.4)
result[students[i]] = wavg
print(result)
print("Jack Details:")
print(result['Jack'])
Students = ['Bill', 'Sue', 'Janet', 'Cindy', 'Ray', 'Jack',
'Barbra', 'Matt', 'Joey', 'Adam', 'Becky', 'Mona']
Exam1 = [100, 80, 26, 45, 89, 65, 92, 75, 76, 15, 80, 50]
Exam2 = [88, 95, 55, 60, 81, 25, 70, 100, 95, 70, 72, 10]
Exam3 = [65, 92, 100, 80, 26, 92, 55, 60, 80, 55, 60, 75]
scaleExamOne = 0.3
scaleExamTwo = 0.3
scaleExamThree = 0.4
waverage(Students,Exam1,Exam2,Exam3,scaleExamOne,scaleExamTwo,scaleExamThree)
Execution screenshots: