ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(10 % 3.5, -10 % 3.5, 10 // 3.5, round(-1.5), round(0.5) + round(1.5))
- A. 3.0 0.5 2.0 -1 2
- B. 3.0 0.5 2.0 -2 1
- C. 2.0 0.5 2.0 -2 2
- D. 3.0 0.5 2.0 -2 2
Correct answer: D. 3.0 0.5 2.0 -2 2
The % result takes the sign of the divisor, so -10 % 3.5 is 0.5, and 10 // 3.5 is 2.0. round uses half-to-even, so round(-1.5) is -2, and round(0.5) + round(1.5) is 0 + 2.
More Python Programming questions
- What is printed? python print(divmod(7.5, 2), 7.5 % -2, -7.5 // 2)
- 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)