ProgrammingVery hardGATE CS & IT · Infosys
What is printed?
What is printed?
print(divmod(-9, 4), -9 % 4, round(-9 / 4))
- A. (-2, 1) 3 -2
- B. (-3, 3) -1 -3
- C. (-3, 3) 3 -3
- D. (-3, 3) 3 -2
Correct answer: D. (-3, 3) 3 -2
divmod and % floor the quotient, so -9 divided by 4 gives -3 with remainder 3. round(-2.25) rounds to the nearest integer, which is -2.
More Python Programming questions
- What is printed? python print(len(str(float(1016))), str(1016 1.0), len(str(1016)))
- What is printed? python print(0.1 + 0.7 == 0.8, 0.8 - 0.7, 0.3 / 0.1, int(0.3 / 0.1))
- What is printed? python print(1.0 == 1, 1.5 // 0.5, 1.5 % 0.4, 2.0 -1074 > 0, 2.0 -1075 == 0)
- What is printed? python print(float.fromhex('0x1p-2'), 0.25 == float.fromhex('0x1p-2'), float.fromhex('0x1.8p1'))
- What is printed? python print(divmod(10, 3)[::-1], divmod(-10, 3)[::-1], divmod(10, -3)[::-1])
- What is printed? python print(-5 % 3 == 1, 5 % -3 == -1, -5 // -3, 5 // -3)