ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(-17 % -5, 17 % -5, -17 % 5, -(17 % 5))
- A. -2 -3 3 -3
- B. -2 3 4 -2
- C. -3 -3 3 -2
- D. -2 -3 3 -2
Correct answer: D. -2 -3 3 -2
The remainder takes the sign of the divisor. -17 % -5 is -2, 17 % -5 is -3, and -17 % 5 is 3. The unary minus in the last value is applied after the % operation.
More Python Programming questions
- What is printed? python a = 'ab' b = a 3 print(b.count('ab'), b.count('aba'), len(b.split('b')))
- What is printed? python print(0.1 10 == 1.0, 0.1 10, sum([0.1] 10) == 1)
- What is printed? python print(int(1e15 + 0.3) == 1015, round(1e15 + 0.3) - 1015)
- What is printed? python print(10.01, 0x1F, 1000.0e-3)
- What is printed? python print(str(1e100)[:6], len(str(1e100)), 1e100 == 10100)
- What is printed? python print(divmod(-1, 1020), divmod(1020, -1))