ProgrammingHardProduct-company MCQ pattern
What is printed on the first line?
What is printed on the first line?
print(7 % -3, -7 % 3, 7 % 3, -7 % -3) print(-7 // -3, 7 // -3, -7 // 3)
- A. -2 2 1 -1
- B. -1 2 1 -2
- C. -2 2 1 -3
- D. -2 3 1 -1
Correct answer: A. -2 2 1 -1
The remainder takes the sign of the divisor, so 7 % -3 is -2 and -7 % -3 is -1. Floor division of negative values rounds down, not toward zero.
More Python Programming questions
- What is printed on the second line? python def mod(a, m): r = a % m return r + m if r < 0 else r print(mod(-1, 5), mod(-5, 5), mod(-6, 5))…
- What is printed on the first line? python M = 109 + 7 print((-1) % M, (262) % M, pow(3, M - 2, M) 3 % M) print(((-5) % 3) ((-5) % 3), (-5…
- What is printed on the second line? python a, b = -13, 4 print(a // b, a % b, a // b b + a % b == a) print(int(a / b), int(-3.25), -3.25…
- What is printed on the first line? python n = -17 print(n >> 2, n // 4, n & 3, n % 4) print(n << 1, (n << 1) >> 1 == n, ~n)
- What is printed on the first line? python x = 1 for in range(70): x = 2 print(x, x.bitlength(), x == 270) print(x.bitlength() - 1, (x…
- What is printed on the first line? python import math print(math.factorial(20) == 2432902008176640000, len(str(math.factorial(25))))…