ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(1 + 2 * 3 ** 2 // 4 % 5, (1 + 2) * 3 ** 2 // 4 % 5, -2 ** 2, (-2) ** 2)
- A. 5 1 -4 4
- B. 5 1 -8 4
- C. 6 1 -4 4
- D. 5 4 -4 4
Correct answer: A. 5 1 -4 4
** binds tightest, then *, // and % from left to right, and + last. So 2 * 9 // 4 % 5 is 4 and 1 + 4 is 5. -2 ** 2 is -(2 ** 2), and (-2) ** 2 is 4.
More Python Programming questions
- What is printed? python print(max('zebra', 'Zebra'), min('zebra', 'Zebra'), 'apple' > 'Apple', 'Z' < 'a')
- What is printed? python x = 5 print(x.add(3), (5).mod(-3), (-5).mod(3), int.floordiv(-5, 3))
- What is printed? python print('ab'.rjust(5, ''), 'ab'.ljust(5, '-'), 'ab'.center(5, '.'), 'ab'.center(6, '.'))
- What is printed? python print(f'{"x"!r}', '%s and %r' % ('x', 'x'), '{!s} {!r}'.format('x', 'x'))
- What is printed? python s = 'abc' print(s 2 == 'abcabc', s[1:] + s[:1], s[-1:] + s[:-1], len('ab' 0))
- What is printed? python print(int('007'), int('-07'), int('01'), int('00'))