ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(divmod(7, 2), divmod(-7, 2), divmod(7.5, 2))
- A. (3, 1) (-4, 1) (3, 1.5)
- B. (3.5, 1) (-4, 1) (3.0, 1.5)
- C. (3, 1) (-4, 1) (3.0, 1.5)
- D. (3, 1) (-3, -1) (3.0, 1.5)
Correct answer: C. (3, 1) (-4, 1) (3.0, 1.5)
divmod uses floor division, so -7 divided by 2 gives -4 with remainder 1. With a float argument, the quotient is returned as a float, 3.0.
More Python Programming questions
- What is printed? python def outer(): res = [] for i in range(3): res.append(lambda: i) return [f() for f in res] def outer2(): return…
- What is printed? python print(10 18 % 7, (10 18 + 2) // 4, -(2 63) // (2 62))
- What is printed? python lst = list(range(5)) lst[1:4] = [] try: lst[::2] = [9, 9] except ValueError: print('ValueError', lst)
- What is printed? python def dedupe(a): if not a: return 0 k = 1 for i in range(1, len(a)): if a[i] != a[k - 1]: a[k] = a[i] k += 1 return…
- What is printed? python def firsttrue(lo, hi, ok): while lo < hi: mid = (lo + hi) // 2 if ok(mid): hi = mid else: lo = mid + 1 return lo…
- What is printed? python def search(a, t): lo, hi = 0, len(a) - 1 while lo <= hi: mid = (lo + hi) // 2 if a[mid] == t: return mid if a[lo]…