ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(-7 % 4, -7 % -4, 7 % -4, (-7) % 4 == -7 % 4)
- A. 1 -3 -1 True
- B. 1 -3 -1 False
- C. -3 -3 1 True
- D. 1 4 -1 True
Correct answer: A. 1 -3 -1 True
Modulo takes the divisor's sign, so -7 % 4 is 1 and 7 % -4 is -1. -7 % -4 is -3, and the parentheses change nothing because unary minus on a literal binds to 7 first.
More Python Programming questions
- What is printed? python def edit(a, b): dp = [[0] (len(b) + 1) for in range(len(a) + 1)] for i in range(len(a) + 1): for j in range(len(b)…
- What is printed? python def lcs(a, b): dp = [[0] (len(b) + 1) for in range(len(a) + 1)] for i in range(1, len(a) + 1): for j in range(1…
- What is printed? python from itertools import accumulate a = [2, -1, 3] P = list(accumulate(a, initial=0)) print(P, P[3] - P[1])
- What is printed? python from itertools import combinations print(sum(1 for r in range(5) for c in combinations([1, 2, 3, 4], r) if sum(c)…
- What is printed? python print([i ^ (i >> 1) for i in range(4)])
- What is printed? python print(pow(6, -1, 11), pow(4, -1, 9))