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]])
- A. ['F', 'F', 'B', 'B', 'A']
- B. ['F', 'D', 'B', 'B', 'A']
- C. ['F', 'D', 'B', 'A', 'A']
- 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
- What is printed? python x = [1, 2, 3] y = [x, x] y[0] = y[0] + [4] y[1] += [5] print(x, y)
- What is printed? python def f(a, b=[]): b = b + [a] f.defaults = (b,) return b print(f(1), f(2), f(3, []), f(4))
- What is printed? python it = (x x for x in range(5)) first = next(it) rest = [v for v in it if v % 2 == 0] again = sum(1 for in it)…
- What is printed? python def g(): for i in range(3): try: yield i finally: print(f"f{i}", end=" ") for v in g(): if v == 1: break…
- What is printed? python def deco(cls): orig = cls.init def init(self, a): orig(self, a) self.ok = True cls.init = init return cls @deco…
- What is printed? python import functools @functools.singledispatch def show(x): return "obj" @show.register def (x: int): return "int"…