Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Doc/library/bisect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ example uses :py:func:`~bisect.bisect` to look up a letter grade for an exam sco
based on a set of ordered numeric breakpoints: 90 and up is an 'A', 80 to 89 is
a 'B', and so on::

>>> def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
... i = bisect(breakpoints, score)
... return grades[i]
>>> def grade(score)
... i = bisect([60, 70, 80, 90], score)
... return "FDCBA"[i]
...
>>> [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
['F', 'A', 'C', 'C', 'B', 'A', 'A']
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ class TestErrorHandlingC(TestErrorHandling, unittest.TestCase):

class TestDocExample:
def test_grades(self):
def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
i = self.module.bisect(breakpoints, score)
return grades[i]
def grade(score):
i = self.module.bisect([60, 70, 80, 90], score)
return "FDCBA"[i]

result = [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
self.assertEqual(result, ['F', 'A', 'C', 'C', 'B', 'A', 'A'])
Expand Down
Loading