# inefficient.py: # Author: James Tam # Version: January 25, 2008 # A program that conerts a numeric gpa to a letter grade. The current version # of the program assumes that only integer gpa values will be used and # will truncate any real number values entered. # 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. print "Input GPA as an integer: ", gpa = input() letter = 'W' if (gpa == 4): print "Letter grade is an A" "Great job!" letter = 'A' if (gpa == 3): print "Letter grade is a B" print "Good job" letter = 'B' if (gpa == 2): writeln('Letter grade is a C'); writeln('Average grade'); letter = 'C'; if (gpa == 1): print "Letter grade is a D" print "Better luck next time." letter = 'D' if (gpa == 0): print "Letter grade is an F" print "Try again kid." letter = 'F' print "GPA: ", gpa, "\t", "Letter: ", letter