ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(divmod(-7, 3), divmod(7, -3), divmod(-8.5, 4))
- A. (-3, 2) (-2, -2) (-3.0, 3.5)
- B. (-2, 1) (-3, -2) (-3.0, 3.5)
- C. (-3, 2) (-3, -2) (-3.0, 3.5)
- D. (-3, 2) (-3, -2) (-2.0, 3.5)
Correct answer: C. (-3, 2) (-3, -2) (-3.0, 3.5)
divmod floors the quotient and gives the remainder the divisor's sign: -7 = (-3)(3) + 2 and 7 = (-3)(-3) + (-2). For floats the quotient is -3.0 and the remainder is 3.5.
More Python Programming questions
- What is printed? python print(abs(-7) // 2 -1, -abs(-7) // 2, -(abs(-7) // 2))
- What is printed? python x = 255 print(f'{x:08b}', f'{x:o}', f'{x:X}', f'{x:#010x}')
- What is printed? python print(int('11', 2) + int('11', 8) + int('11', 16))
- What is printed? python print(round(1234.5678, -2), round(-1234.5678, 2), round(0.000123456, 5))
- What is printed? python print(7 / 7, 0 / 5, -0 / 5, 2 0, 0 0.0)
- What is printed? python print(7 // 1.0 1, 1e3 // 7, -1e3 // 7, 10 % -3.0)