ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(7 // 2 * 2 + 7 % 2 == 7, -(7 // 2) * 2 + -(7 % 2) == -7, (-7) // 2 * 2 + (-7) % 2)
- A. True True -6
- B. True True -7
- C. True False -7
- D. False True -7
Correct answer: B. True True -7
For any sign, a == (a // b) * b + a % b holds in Python, so the last value is -4 * 2 + 1 = -7. Languages that truncate toward zero would give -6 + (-1) and break the identity.
More Python Programming questions
- What is printed? python print(int('12' '34') + 1, '%d' % 3.9, '%i' % -3.9, '%+d' % 0)
- Which approach removes duplicates from a list while keeping the first-seen order, in O(n) average time?
- Which statement about sorting 10^6 floats with sorted() in CPython is correct?
- Which operation is O(1) amortised in CPython?
- What is printed? python from functools import lrucache @lrucache(maxsize=None) def f(a, b=0): return a + b f(1, 2) f(1, b=2) f(1)…
- What is printed? python from collections import OrderedDict od = OrderedDict() for k in ['a', 'b', 'c']: od[k] = ord(k) od.movetoend('a')…