Sep-20-2016, 01:32 PM
Old convert grades problem without if,elif.., using Bisect.
import bisect def grade(total): return grades[bisect.bisect(breakpoints, total)] if __name__ == '__main__': # F is 30 or lower,45-60 is E ect... grades = "FEDCBA" breakpoints = [30, 45, 60, 75, 85] # Students heroes = dict(Superman=90, Hulk=25, Batman=50) for k,v in heroes.items(): print('{} had score of: {} which is grad: {}'.format(k, v, grade(v))) '''Output--> Hulk had score of: 25 which is grad: F Batman had score of: 50 which is grad: D Superman had score of: 90 which is grad: A '''