ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(3 // 2 * 2 + 3 % 2, -3 // 2 * 2 + -3 % 2)
- A. 3 -3
- B. 3 2
- C. 2 -3
- D. 3 -4
Correct answer: A. 3 -3
For both signs a == (a // b) * b + a % b holds, so the first value is 3 and the second is -3. Floor division of -3 by 2 is -2, and -3 % 2 is 1, which gives -4 + 1 = -3.
More Python Programming questions
- What is printed? python print('%s and %r' % ('a', 'a'))
- What is printed? python print('-'.join(map(str, range(3, 0, -1))))
- What is printed? python print('abc'[-1:-4:-1], 'abc'[5:], 'abc'[-10:2])
- What is printed? python print(ord('A') + 1, chr(ord('a') - 32))
- What is printed? python print(divmod(7, -2), 7 % -2)
- What is printed? python print(sum([[1], [2, 3]], []))