Build a GPA calculator that inputs grades of 3 different subjects along with the credit hours
from the user and displays the user’s GPA. The input grades and their corresponding grading
points are given below.Grade Points
A 4.0
A- 3.67
B+ 3.33
B 3.0
B- 2.67
C+ 2.33
C 2.0
C- 1.67
D+ 1.33
D 1.0
F 0
gradesPoints={"A":4.0, "A-": 3.67, "B+": 3.33, "B": 3.0, "B-": 2.67,"C+": 2.33,"C": 2.0, "C-":1.67, "D+":1.33, "D": 1.0, "F":0}
grades=[]
sumGradeCreditHoursProduct=0.0
sumCreditHours=0.0
for i in range(1,4):
grade=input(f"Enter the grade for subject {i}: ")
hours=float(input(f"Enter the credit hours for subject {i}: "))
sumGradeCreditHoursProduct+=gradesPoints[grade]*hours
sumCreditHours+=hours
GPA=sumGradeCreditHoursProduct/sumCreditHours
print("Your GPA: {:.2f}".format(GPA))
Comments
Leave a comment