ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import math print(math.floor(-2.5), math.trunc(-2.5), -7.5 // 2, divmod(7.5, 2))
- A. -3 -2 -4.0 (3.0, 1.5)
- B. -2 -2 -4.0 (3.0, 1.5)
- C. -3 -3 -4.0 (3.0, 1.5)
- D. -3 -2 -3.0 (3.0, 1.5)
Correct answer: A. -3 -2 -4.0 (3.0, 1.5)
floor rounds toward minus infinity and trunc rounds toward zero. Float floor division also floors, and divmod returns the floored quotient as a float with remainder 1.5.
More Python Programming questions
- What is printed? python def dfs(g, s): seen, out, st = set(), [], [s] while st: u = st.pop() if u in seen: continue seen.add(u)…
- What is printed? python def hanoi(n, a, b, c, out): if n == 0: return hanoi(n - 1, a, c, b, out) out.append((a, c)) hanoi(n - 1, b, a, c…
- What is printed? python from collections import deque def islands(g): R, C = len(g), len(g[0]) seen = set() cnt = 0 for r in range(R): for…
- What is printed? python import heapq def refuel(target, start, stations): h = [] i = 0 fuel = start stops = 0 while fuel < target: while i…
- What is printed? python import heapq def jobs(items): items = sorted(items, key=lambda x: x[0]) h = [] for d, p in items…
- What is printed? python try: print(sorted([3, None, 1])) except TypeError: print('TypeError') print(max(['b', 'a'], key=str.upper)…