ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(divmod(-7, 2), divmod(7, -2.0), 7 // -2.0, -7 % 2.5)
- A. (-4, 1) (-3.0, -1.0) -4.0 0.5
- B. (-4, 1) (-4.0, -1.0) -4.0 0.5
- C. (-4, -1) (-4.0, -1.0) -3.0 0.5
- D. (-3, 1) (-4.0, -1.0) -4.0 0.5
Correct answer: B. (-4, 1) (-4.0, -1.0) -4.0 0.5
divmod(-7, 2) floors -3.5 to -4, leaving a remainder of 1. The float version divides 7 by -2.0 to give quotient -4.0 and remainder -1.0, and -7 % 2.5 is 0.5 with the sign of the divisor.
More Python Programming questions
- What is printed? python x = -17 print(x // 5, x % 5, divmod(x, -5), x.mod(5))
- What is printed? python print(1018 + 1 == 1000000000000000001, 231 - 1 + 1, -(231), (231) (231) == 262)
- What is printed? python s = 'a' for i in range(3): s = s + s[::-1] + str(i) print(s, len(s))
- What is printed? python t = (1, 2, 3) t += (4,) u = t t = 2 print(t, u, t is u, len(t) len(u))
- What is printed? python lst = [1, 2, 3] lst2 = lst lst = 2 lst2 += [9] print(lst, lst2, lst is lst2)
- What is printed? python print(f'{0.1 + 0.2:.17g}', f'{1/7:.10f}', f'{100/3:.0f}', f'{2.345:.2f}')