GPA Calculator using Python
Posted by Samath
Last Updated: January 20, 2024

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))

 

Related Content
GPA Calculator using C#
GPA Calculator using C#
Samath | Jan 01, 2021
Simple GPA calculator in Java
Simple GPA calculator in Java
Samath | Jan 17, 2024
GPA Calculator in C++
GPA Calculator in C++
Samath | Jan 17, 2024
C Program that calculates GPA
C Program that calculates GPA
Samath | Jan 20, 2024
Simple Calculator using C#
Simple Calculator using C#
Samath | Dec 30, 2020
Calculator Program in Java
Calculator Program in Java
Samath | Jan 07, 2021
Simple C++ Calculator
Simple C++ Calculator
Samath | Jan 05, 2017
Simple Calculator using Python
Simple Calculator using Python
Samath | Jan 09, 2017
Scientific Calculator using C#
Scientific Calculator using C#
Samath | Jan 08, 2021