ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(-7 // -2, 7 // -2 * -2 + 7 % -2)
- A. 2 7
- B. 4 7
- C. 3 7
- D. 3 1
Correct answer: C. 3 7
-7 // -2 floors 3.5 to 3. For 7 // -2, floor division gives -4, and 7 % -2 is -1, so (-4) * (-2) + (-1) = 7. The identity a == (a // b) * b + a % b always holds.
More Python Programming questions
- What is printed? python print(round(-2.5), round(-3.5), round(7, -1), round(15, -1), round(25, -1))
- What is printed? python print(int('12abc', 36), int('zz', 36), int('-z', 36))
- What is printed? python print(hash(-1) == hash(-2), hash(-1), hash(261 - 1))
- What is printed? python print(int.bitlength(-255), (255).bitlength(), (256).bitlength())
- What is printed? python print(chr(0x1F600) == '😀', len('😀'), len('😀'.encode('utf-16-le')))
- What is printed? python print(10400 > float('inf'), float('inf') > 10400, float(10308) == 10308)