# efficient.py: # Author: James Tam # Port to Python 3.X: September 15, 2011 # Original version: January 25, 2008 # A program that conerts a letter grade to numeric GPA. # Note: This program is more efficient than the inefficient # version because once the first GPA match is found the other # cases won't be checked. letter = input("Enter whole letter grade (A,B,C,D,F): ") gpa = -1 if (letter == "A"): print("Great job!") gpa = 4 elif (letter == "B"): print("Good job") gpa = 3 elif (letter == "C"): print("Average grade") gpa = 2 elif (letter == "D"): print("Min pass") gpa = 1 elif (letter == "F"): print ("Failing grade") gpa = 0 else: print ("GPA must be one of 'A', 'B', 'C', 'D' or 'F'") print ("GPA: %d" %gpa, "\t", "Letter: %s" %letter)