ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(-7 // 2, -7 % 2, -7 // 2 * 2 + -7 % 2)
- A. -3 1 -7
- B. -4 1 -7
- C. -3 1 -6
- D. -4 2 -7
Correct answer: B. -4 1 -7
Floor division rounds toward negative infinity, so -7 // 2 is -4, and the remainder takes the divisor's sign, giving -7 % 2 = 1. The identity a == (a // b) * b + a % b holds, so the last value is -7.
More Python Programming questions
- What is printed? python print(7 // -2, -7 // 2, 7 % -2, divmod(-7, -2))
- What is printed? python print(round(2.5), round(3.5), round(-0.5), round(0.5 + 1e-16))
- What is printed? python print('ß'.upper(), 'Dž'.lower(), len('ß'.upper()), 'İ'.lower() == 'i')
- What is printed? python import math print(f'{-0.0}', -0.0 == 0.0, math.copysign(1, -0.0))
- What is printed? python print(1 == 1.0, hash(1) == hash(1.0), {1: 'a'}[1.0], True + 1.0)
- What is printed? python print(sorted([3, -3, 2, -2, 1], key=abs))