ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(divmod(7, -2), 7 % -2)
- A. (-2, 1) 3
- B. (-4, 2) 1
- C. (-4, -1) -1
- D. (-3, -1) -1
Correct answer: C. (-4, -1) -1
Floor division gives -4 for 7 / -2 rounded toward minus infinity, and the remainder takes the sign of the divisor, so 7 - (-4)(-2) = -1.
More Python Programming questions
- What is printed? python print(sum([[1], [2, 3]], []))
- What is printed? python x = (1, [2]) x[1].append(3) print(x)
- What is printed? python print(max([1, 5, 3], key=lambda v: -v))
- What is printed? python print(list(map(int, '1 2 3'.split()))[::-1])
- What is printed? python print(f'{7:03d}|{-7:d}|')
- What is printed? python x = 7 print(f'{x=}', f'{x 2 = }', f'{"a"!r:>4}')