擅长:python、mysql、java
<p>你可以用<a href="https://docs.python.org/3/library/bisect.html" rel="nofollow noreferrer">bisect</a>来做这个。你知道吗</p>
<pre><code>from bisect import bisect
def get_rank(score):
points = [500, 1000, 1500, 2500, 3000]
ranks = ["Private", "Private I", "Private II", "Private III", "Corporal"]
div = bisect(points, score)
return ranks[div]
</code></pre>