ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(divmod(-17, 5), divmod(17, -5), divmod(-17.0, 5))
- A. (-3, 3) (-4, -3) (-4.0, 3.0)
- B. (-4, 3) (-3, -2) (-4.0, 3.0)
- C. (-4, 3) (-4, -3) (-4.0, 3.0)
- D. (-4, 3) (-4, -3) (-4, 3)
Correct answer: C. (-4, 3) (-4, -3) (-4.0, 3.0)
divmod floors the quotient and gives the remainder the sign of the divisor. -17 = (-4)(5) + 3, and 17 = (-4)(-5) + (-3). The float version returns floats, so the quotient is -4.0.
More Python Programming questions
- What is printed? python print(7 // -2, -7 // 2, 7.0 // -2, -7.0 % 2)
- What is printed? python print(abs(-0.0), -0.0 == 0.0, str(-0.0), str(-0.0 + 0.0))
- What is printed? python print(sum([0.1] 10) == 1.0, sum([0.1] 10), sum([0.1] 10, 0) == 1.0)
- What is printed? python print(int(3.9999999999999999), int(-3.7), round(-3.7))
- What is printed? python print(hash(1) == hash(1.0), hash(True) == 1, {1: 'a', 1.0: 'b', True: 'c'})
- What is printed? python print(0.1 3 == 0.3, 0.1 3, 0.3 3 == 0.9)