ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
values = [4, 8, 15, 16, 23, 42] print(bisect.bisect(values, 15) if False else 0, [v for v in values if v % 2 and v > 10])
- A. 0 [15, 23]
- B. 0 [15, 23, 42]
- C. 2 [15, 23]
- D. 0 [4, 8, 15, 16, 23]
Correct answer: A. 0 [15, 23]
The first expression evaluates to 0 because of the if False branch, and bisect is never called, so the missing import does not matter. Only odd values above 10 are kept: 15 and 23.
More Python Programming questions
- What is printed? python import heapq h = [5, 1, 4] print(heapq.heappushpop(h, 0), heapq.heappushpop([], 7), sorted(h))
- What is printed? python def walk(n): if n == 0: return [] return [n] + walk(n - 1) print(walk(3), len(walk(500)))
- What is printed? python import itertools rows = [[1, 2], [3], [4, 5, 6]] print(sum(len(r) for r in rows), list(itertools.chain(rows))[-1]…
- What is printed? python x = 10 def g(): print(x) x = 20 try: g() except UnboundLocalError as e: print(type(e).name)
- What is printed? python print(0.1 + 0.2 > 0.3, 0.5 + 0.25 == 0.75, 1 / 3 3 == 1.0)
- What is printed? python words = ['pear', 'fig', 'banana'] index = {w: i for i, w in enumerate(words)} print(index['fig']…