GPA Calculator using Python

Posted by Samath
  958
January 09, 2017

 

This is a simple GPA Calculator using the python programming language. The program calculate the GPA for 7 subject, but it can be change to any amount of subjects needed. The program ask the user for 7 letter grades and the amount of credits for each subject then use these entered value to calculate the GPA.

lettergrd = " "
credit = 0.0
caltimes = 0.0
totalcal = 0.0
totalcredit = 0.0
finalgpa = 0.0
A = 4.0
AMINUS = 3.67
BPLUS = 3.33
B = 3.0
BMINUS = 2.67
CPLUS = 2.33
C = 2.0
CMINUS = 1.67
D = 1.00
F = 0.0
                
for i in range(0,7):
    lettergrd = raw_input("\nPlease enter the letter grade: ")
    credit = raw_input("Please enter the course credit: ")
    if(lettergrd == "A" or lettergrd == "a"):
        caltimes = float(credit) * A
    elif(lettergrd == "A-" or lettergrd == "a-"):
        caltimes = float(credit) * AMINUS
    elif(lettergrd == "B+" or lettergrd == "b+"):
        caltimes = float(credit) * BPLUS
    elif(lettergrd == "B" or lettergrd == "b"):
        caltimes = float(credit) * B
    elif(lettergrd == "B-" or lettergrd == "b-"):
        caltimes = float(credit) * BMINUS
    elif(lettergrd == "C+" or lettergrd == "c+"):
        caltimes = float(credit) * CPLUS
    elif(lettergrd == "C" or lettergrd == "c"):
        caltimes = float(credit) * C
    elif(lettergrd == "C-" or lettergrd == "c-"):
        caltimes = float(credit) * CMINUS
    elif(lettergrd == "D" or lettergrd == "d"):
        caltimes = float(credit) * D
    elif(lettergrd == "F" or lettergrd == "f"):
        caltimes = float(credit) * F

    totalcredit = totalcredit + float(credit)
    totalcal = totalcal + caltimes
                
finalgpa = totalcal/totalcredit
print("\nGPA: " + str(finalgpa))