ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(10 % 4 == 2, -10 % 4 == 2, 10 // -4, 10 / -4)
- A. True True -2 -2.5
- B. False False 3 -2.5
- C. True False -3 -2.5
- D. True False -2 -2.5
Correct answer: C. True False -3 -2.5
10 % 4 is 2. With a positive divisor, -10 % 4 is 2 as well, because the result takes the divisor's sign, so the second check is True and the remainder is not -2. Floor division of 10 by -4 is -3, and 10 / -4 is -2.5.
More Python Programming questions
- What is printed? python s = 'abcdef' print(s[-2:], s[:-2], s[-10:], s[::-2][0])
- What is printed? python print('abc' < 'abd' and 'x' or 'y', [] or 'empty', 0 or 0.0 or 'z')
- What is printed? python print(len({'a': 1, 'a': 2}), {'a': 1, 'a': 2}, list({1, 2, 1}), sorted({3, 1, 2} & {2, 3, 4}))
- What is printed? python print('Ab'.swapcase(), 'ab'.capitalize() == 'Ab', 'AB'.lower() == 'ab', 'a b'.title())
- What is printed? python print(3 > 2 > 1, 3 > 2 and 2 > 1, (3 > 2) + (2 > 1))
- What is printed? python print(sorted([0.5, 1, True, False]), max(0.5, 1, True))