ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
import bisect
grades = "FDCBA"
cut = [60, 70, 80, 90]
print([grades[bisect.bisect(cut, s)] for s in [59, 60, 85, 90, 100]])
  1. A. ['F', 'F', 'B', 'B', 'A']
  2. B. ['F', 'D', 'B', 'B', 'A']
  3. C. ['F', 'D', 'B', 'A', 'A']
  4. D. ['D', 'C', 'A', 'A', 'A']

Correct answer: C. ['F', 'D', 'B', 'A', 'A']

bisect (bisect_right) returns the insertion point AFTER any equal entries, so a score exactly at a cutoff moves up a grade: 60 gives index 1 ('D') and 90 gives index 4 ('A').

More Python Programming questions

Exams that ask this topic