I would use a dictionary for this rather than adding multiple elif statements. It's easier to add new cases and is easier to read.
There's also no need to add items to a "grade" array if you use the dictionary approach as you can look up the key's (grade) value (score) straight away.
Removing the while loop means we don't need the y variable.
Applying the .upper() method to the input straight away makes it more readable in my oppinion.
total = 0 grade_dictionary = { "A+":4.0, "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.0, } for _ in range(6): grade = input("Enter Your Grade For Each Class Listed in Order (Letter Form): ").upper() total += grade_dictionary.get(grade, 0) print(total / 6)
y = 0while (y <=5):grade = input("Enter Your Grade For Each Class Listed in Order (Letter Form): ")grade = grade.upper()grades.append(grade)y = y + 1calculate()- total = 0
def calculate():total= 0for element in grades:if element == "A+":total = total + 4.0elif element == "A":total = total + 4.0elif element == "A-":total = total + 3.7elif element == "B+":total = total + 3.3elif element == "B":total = total + 3.0elif element == "B-":total = total + 2.7elif element == "C+":total = total + 2.3elif element == "C":total = total + 2.0elif element == "C-":total = total + 1.7elif element == "D":total = total + 1.0gpa = total / 6print(gpa)- grade_dictionary = {
- "A+":4.0,
- "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.0,
- }
collect()- for _ in range(6):
- grade = input("Enter Your Grade For Each Class Listed in Order (Letter Form): ").upper()
- total += grade_dictionary.get(grade, 0)
- print(total / 6)