ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(10 % 3 ** 2, 10 % (3 ** 2), (10 % 3) ** 2, -10 % 3 ** 2)
- A. 1 1 1 8
- B. 1 1 1 -1
- C. 1 1 9 8
- D. 1 1 1 9
Correct answer: A. 1 1 1 8
** binds tighter than %, so each expression uses 3 ** 2 = 9 as the modulus. -10 % 9 is 8, because the result takes the sign of the divisor.
More Python Programming questions
- What is printed? python print(list(range(10, 0, -3)), list(range(-1, -10, -4)), len(range(0, 10, 3)), range(5)[-1])
- What is printed? python print(len('anb'), len('anb'), len(r'anb'), len('arb'))
- What is printed? python print(8 % -3, -8 % -3, 8 // -3, -8 // -3)
- What is printed? python t = str.maketrans('abc', 'xyz') print('aabbcc'.translate(t), len(t))
- What is printed? python import heapq h = [5, 1, 3, 1] heapq.heapify(h) print(h[0], heapq.heappop(h), heapq.nsmallest(2, [4, -1, 3])…
- What is printed? python from functools import reduce print(reduce(lambda a, b: a 10 + b, [1, 2, 3]), reduce(lambda a, b: a - b, [10, 2…