ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(divmod(7.5, 2), divmod(-7.5, 2), 7.5 % -2, -7.5 // -2)
- A. (3.0, 1.5) (-4.0, 0.5) -0.5 3.0
- B. (3.0, 1.5) (-4.0, 0.5) -0.5 4.0
- C. (3.0, 1.5) (-3.0, 0.5) -0.5 3.0
- D. (3.0, 1.5) (-4.0, 0.5) 0.7 3.0
Correct answer: A. (3.0, 1.5) (-4.0, 0.5) -0.5 3.0
Float divmod uses the same floor rules as ints, so 7.5 divided by 2 is 3.0 with remainder 1.5. The remainder of 7.5 by -2 takes the divisor's sign, -0.5, and -7.5 // -2 floors 3.75 to 3.0.
More Python Programming questions
- What is printed? python print(-7 % 4, -7 % -4, 7 % -4, (-7) % 4 == -7 % 4)
- What is printed? python def edit(a, b): dp = [[0] (len(b) + 1) for in range(len(a) + 1)] for i in range(len(a) + 1): for j in range(len(b)…
- What is printed? python def lcs(a, b): dp = [[0] (len(b) + 1) for in range(len(a) + 1)] for i in range(1, len(a) + 1): for j in range(1…
- What is printed? python from itertools import accumulate a = [2, -1, 3] P = list(accumulate(a, initial=0)) print(P, P[3] - P[1])
- What is printed? python from itertools import combinations print(sum(1 for r in range(5) for c in combinations([1, 2, 3, 4], r) if sum(c)…
- What is printed? python print([i ^ (i >> 1) for i in range(4)])