Answer to Question #178329 in Python for tas

Question #178329

Assume, it is the end of the semester and the students would like to know the GPA they achieved for the subjects they registered and sit for the final exam. You are going to develop a program that can calculate GPA for the students according to the grade they get and the subject credit hours. The point scale for the grade is shown below. Grade Point Scale A 4.0, A- 3.7 ,B+ 3.3, B 3.0, B- 2.7, C+ 2.3, C 2.0, C- 1.7, D+ 1.3, D 1.0, D- 0.7, F= 0 Note the formulae below to calculate the GPA. 𝐺𝑃𝐴 = 𝒔𝒖𝒎 𝒐𝒇 (𝒔𝒖𝒃𝒋𝒆𝒄𝒕 𝒄𝒓𝒆𝒅𝒊𝒕 𝑥 𝒈𝒓𝒂𝒅𝒆 𝒑𝒐𝒊𝒏𝒕) / 𝒕𝒐𝒕𝒂𝒍 𝒄𝒓𝒆𝒅𝒊𝒕 𝒂𝒕𝒕𝒆𝒎𝒑𝒕𝒆𝒅 Please make sure to apply the loop concept. 


1
Expert's answer
2021-04-07T09:47:30-0400
def main():
    #Read number of subjects 
    numberSubjects=int(input("How many subjects have you registered?: "))
    sumGradePoint=0
    totalCredits=0
    for i in range(0,numberSubjects):
        #Read grade
        subjectGrade=input("Enter the grade [A , A-, B+, B, B-, C+, C, C-, D+, D, D-, F]: ")
        #Read the subject credit hours
        creditHours=int(input("Enter the subject credit hours: "))
        gradePoint=getGradePoint(subjectGrade)
        #calculate sum grade point
        sumGradePoint+=creditHours*gradePoint
        totalCredits+=creditHours
    #calculate GPA
    GPA=sumGradePoint/totalCredits
    #Display GPA
    print("GPA = "+"{:.2f}".format(GPA))


    
# Get Grade Point Scale A 4.0, A- 3.7 ,B+ 3.3, B 3.0, B- 2.7, C+ 2.3, 
# C 2.0, C- 1.7, D+ 1.3, D 1.0, D- 0.7, F= 0
def getGradePoint(subjectGrade):
    if subjectGrade.upper()=="A":
        return 4.0
    if subjectGrade.upper()=="A-":
        return 3.7
    if subjectGrade.upper()=="B+":
        return 3.3
    if subjectGrade.upper()=="B":
        return 3.0
    if subjectGrade.upper()=="B-":
        return 2.7
    if subjectGrade.upper()=="C+":
        return 2.3
    if subjectGrade.upper()=="C":
        return 2.0
    if subjectGrade.upper()=="C-":
        return 1.7
    if subjectGrade.upper()=="D+":
        return 1.3
    if subjectGrade.upper()=="D":
        return 1.0
    if subjectGrade.upper()=="D-":
        return 0.7
    return 0
    
main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment