Python Forum
Problem Calculating GPA
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem Calculating GPA
#1
Hey all, I have created a simple program to try to convert letter grades into a GPA score, but my program calculations are a bit off.

user_grades = []

grades = str(input("Enter a grade: ('q' to end.)"))
user_grades.append(grades)

while grades != 'q':
    grades = str(input("Enter a grade: ('q' to end.)"))
    user_grades.append(grades)
else:
    user_grades.pop()
    print(f"{user_grades}")
    
total = 0

for grade in user_grades:
    if "A+" in user_grades:
        total += 4.0
    elif "A" in user_grades:
        total += 4.0
    elif "A-" in user_grades:
        total += 3.7
    elif "B+" in user_grades:
        total += 3.3
    elif "B" in user_grades:
        total += 3
    elif "B-" in user_grades:
        total += 2.7
    elif "C+" in user_grades:
        total += 2.3
    elif "C" in user_grades:
        total += 2.0
    elif "C-" in user_grades:
        total += 1.7
    elif "D+" in user_grades:
        total += 1.3
    elif "D" in user_grades:
        total += 1.0
    elif "F" in user_grades:
        total += 0
    print(f"{total}")
Any help would be greatly appreciated.

Thanks!
Larz60+ write Apr-12-2023, 09:51 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I have fixed this for you. Please use BBCode tags on future posts.
Reply


Messages In This Thread
Problem Calculating GPA - by FirstBornAlbratross - Apr-12-2023, 08:19 PM
RE: Problem Calculating GPA - by ibreeden - Apr-13-2023, 10:06 AM
RE: Problem Calculating GPA - by deanhystad - Apr-13-2023, 01:47 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020