# inefficient.py: # Author: James Tam # Python 3.X version: September 15, 2011 # Original Version: January 25, 2008 # Limitation: # *Cannot handle non-numeric input # A program that conerts a letter grade to a numeric GPA. # Note: A program written to illustrate why you should use if- # elif-else statements if you have exclusive multiple # conditions. While this program does produce the same output # as efficient.py it does so in far less efficient fashion # because now every conditional if will be checked even # though only one of them will be true. letter = input("Enter whole letter grade (A,B,C,D,F): ") gpa = -1 if (letter == "A"): print("Great job!") gpa = 4 if (letter == "B"): print("Good job") gpa = 3 if (letter == "C"): print("Average grade") gpa = 2 if (letter == "D"): print("Min pass") gpa = 1 if (letter == "F"): print ("Failing grade") gpa = 0 print ("GPA: %d" %gpa, "\t", "Letter: %s" %letter)