Write a function that calculates the grade point average (GPA) on a scale of 0 t
ID: 3680822 • Letter: W
Question
Write a function that calculates the grade point average (GPA) on a scale of 0 to 4, where A = 4, B = 3, C = 2, D = 1, and F = 0. One input is a list whose elements arc letter grades, A, B, C, D, or F, and the second input is a list whose elements are corresponding credit hours between 1 and 4. One example is: Grade = [B, A, C, F] and Credit = [3, 1, 4, 3]. Create your own lists with about 15 entries in each and calculate the GPA. The output should show your lists for grades, credit hours, and the GPA calculated. Name your fileExplanation / Answer
listGrades = ['A', 'B', 'C', 'D', 'F', 'A', 'B', 'C', 'D', 'F', 'A', 'B', 'C', 'D', 'F'];
listCredits = [3, 1 , 2 , 3, 2, 3, 1 , 2 , 3, 2, 3, 1 , 2 , 3, 2];
dictionary = {'A':4, 'B':3, 'C':2, 'D':1, 'F':0};
total = 0;
maximumCredits = 0;
print ("(grade,credit)");
for i, j in zip(listGrades, listCredits):
print(i, j);
weight = dictionary[i];
total += j * weight;
maximumCredits += j * dictionary['A'];
print ("Student Total Credits : ") ;
print(total);
print ("Maximum Credits : ");
print (maximumCredits);
print ("Student GPA : ");
print ((float(total) / float(maximumCredits)) * dictionary['A']);
Let me know if you required modification.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.