import bisect
def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
i = bisect.bisect(breakpoints, score)
return grades[i]
print([33, 99, 77, 70, 89, 90, 100])
print([grade(score) for score in [33, 99, 77, 70, 89, 90, 100]])
结果 输出如下:
[33, 99, 77, 70, 89, 90, 100]
['F', 'A', 'C', 'C', 'B', 'A', 'A']
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did86388