ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(round(1e16 + 2), round(9.5), round(10.5), round(-9.5))
- A. 10000000000000000 10 11 -10
- B. 10000000000000002 10 11 -10
- C. 10000000000000002 9 10 -10
- D. 10000000000000002 10 10 -10
Correct answer: D. 10000000000000002 10 10 -10
1e16 + 2 is exactly representable, and round of a float that is already whole returns the same integer. Halves go to the even neighbour, so 9.5 and 10.5 both give 10, and -9.5 gives -10.
More Python Programming questions
- What is printed? python print(type(1 / 2).name, type(1 // 2).name, type(2 -1).name, type(2 0.5).name, type(True + 1).name)
- What is printed? python print(sorted(['10', '9', '1.5']), sorted(['10', '9', '1.5'], key=float))
- What is printed? python print(max('the', 'a', key=len), min(['b', 'B'], key=str.lower), ''.join(sorted('cab')), 'cab'.upper().swapcase())
- What is printed? python print(int(str(1020 + 1)[-1]) + len(str(1020)), 1020 + 1 == int(str(1020 + 1)))
- What is printed? python print(divmod(7.5, 2), divmod(-7.5, 2), 7.5 % -2, -7.5 // -2)
- What is printed? python print(-7 % 4, -7 % -4, 7 % -4, (-7) % 4 == -7 % 4)