Created
July 4, 2017 08:16
-
-
Save YaoC/6bf96bd9747247334396a8002f793184 to your computer and use it in GitHub Desktop.
分数到成绩的对应
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bisect | |
def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'): | |
i = bisect.bisect(breakpoints, score) | |
return grades[i] | |
if __name__ == '__main__': | |
grades = [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]] | |
print(grades) | |
# ['F', 'A', 'C', 'C', 'B', 'A', 'A'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment