ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(divmod(7.5, 2), 7.5 % -2, -7.5 // 2)
- A. (3.0, 1.5) -0.5 -4.0
- B. (3.0, 1.5) 1.5 -4.0
- C. (3.0, 1.5) -0.5 -3.0
- D. (3.0, -0.5) -0.5 -4.0
Correct answer: A. (3.0, 1.5) -0.5 -4.0
divmod(7.5, 2) gives quotient 3.0 and remainder 1.5. For a negative divisor the remainder takes the divisor's sign, so 7.5 % -2 is -0.5. Floor division of -7.5 by 2 is -4.0.
More Python Programming questions
- What is printed? python print(f'{0.1:.20f}'[:12], f'{2/3:.3f}', f'{1e22:.0f}', f'{1e23:.0f}')
- What is printed? python print(float(' 10.5 '), float('infinity'), float('-nan') != float('-nan'), float('10'))
- What is printed? python print(len(bytes(3)), bytes([65, 66]) == b'AB', bytearray(b'ab') == b'ab', type(b'a'[0]).name)
- What is printed? python s = 'abc' t = s s += 'd' print(s, t, s is t)
- What is printed? python a = [1, 2] b = a 2 b[0] = 9 c = a + a c[2] = 7 print(a, b, c)
- What is printed on the first line? python grid = [[0] 2] 2 grid[0][0] = 1 print(grid) g2 = [[0] 2 for in range(2)] g2[0][0] = 1 print(g2)