ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
x = -17 print(x // 5, x % 5, divmod(x, -5), x.__mod__(5))
- A. -4 3 (3, -2) 3
- B. -3 -2 (3, -2) 3
- C. -4 3 (2, 3) 3
- D. -4 3 (3, -2) -2
Correct answer: A. -4 3 (3, -2) 3
-17 // 5 floors to -4 and -17 % 5 takes the divisor's sign, giving 3. divmod(-17, -5) gives (3, -2) because -17 = 3 * (-5) + (-2).
More Python Programming questions
- What is printed? python print(1018 + 1 == 1000000000000000001, 231 - 1 + 1, -(231), (231) (231) == 262)
- What is printed? python s = 'a' for i in range(3): s = s + s[::-1] + str(i) print(s, len(s))
- What is printed? python t = (1, 2, 3) t += (4,) u = t t = 2 print(t, u, t is u, len(t) len(u))
- What is printed? python lst = [1, 2, 3] lst2 = lst lst = 2 lst2 += [9] print(lst, lst2, lst is lst2)
- What is printed? python print(f'{0.1 + 0.2:.17g}', f'{1/7:.10f}', f'{100/3:.0f}', f'{2.345:.2f}')
- What is printed? python a = [3, 1, 2] b = sorted(a, key=lambda x: -x) a.sort(reverse=True) print(a == b, a, b)