# efficient.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 # 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. print "Input GPA as an integer: ", gpa = input() letter = 'W' if (gpa == 4): print "Letter grade is an A" "Great job!" letter = 'A' elif (gpa == 3): print "Letter grade is a B" print "Good job" letter = 'B' elif (gpa == 2): writeln('Letter grade is a C'); writeln('Average grade'); letter = 'C'; elif (gpa == 1): print "Letter grade is a D" print "Better luck next time." letter = 'D' elif (gpa == 0): print "Letter grade is an F" print "Try again kid." letter = 'F' else: print "GPA must be one of '4', '3', '2', '1' or '1'" print "GPA: ", gpa, "\t", "Letter: ", letter