Skip to content

Instantly share code, notes, and snippets.

@YaoC
Created July 4, 2017 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YaoC/6bf96bd9747247334396a8002f793184 to your computer and use it in GitHub Desktop.
Save YaoC/6bf96bd9747247334396a8002f793184 to your computer and use it in GitHub Desktop.
分数到成绩的对应
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