ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(8 % -3, -8 % -3, 8 // -3, -8 // -3)
- A. -1 -2 -3 2
- B. -1 -2 -2 2
- C. 2 -2 -3 2
- D. -1 -2 -3 4
Correct answer: A. -1 -2 -3 2
With a negative divisor, % takes the divisor's sign, so 8 % -3 is -1 and -8 % -3 is -2. Floor division rounds toward negative infinity, so 8 // -3 is -3 and -8 // -3 is 2.
More Python Programming questions
- 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…
- What is printed? python print(sum(1 for c in 'a1b22c333' if c.isdigit()), ''.join(c for c in 'a1b22c333' if c.isalpha()), int(''.join(c…
- What is printed? python print(str(0.1 3), repr(0.1 3) == '0.30000000000000004', 0.1 3 == float(repr(0.1 3)))
- What is printed? python print(10-1 + 10-1 + 10-1 == 0.3, 1/10 + 1/10 + 1/10 == 0.3, 10-1 == 1/10)