ProgrammingVery hardTCS NQT · Infosys
What is printed?
What is printed?
print(round(1.005, 2), round(0.285, 2), round(1.45, 1))
- A. 1.0 0.28 1.4
- B. 1.01 0.29 1.5
- C. 1.0 0.29 1.5
- D. 1.01 0.28 1.4
Correct answer: A. 1.0 0.28 1.4
Each decimal literal is stored as a binary double slightly below the halfway point (1.00499..., 0.28499..., 1.44999...). So round() goes down in all three cases, and no decimal intuition applies.
More Python Programming questions
- What is printed? python print('abcdef'[4:1:-2], 'abc'[::-2], 'abc'[-5:], 'abc'[5:] == '')
- What is printed? python import cmath print((-1) 0.5 == 1j, -1 0.5, (-1) 0.5)
- What is printed? python print((-7) % 3, 7 % -3, (-7) % -3, -7 % 3 2)
- What is printed? python print(-6 & 0xFF, -6 | 3, -6 ^ -3, ~-6 >> 1)
- What is printed? python print(len('ab' 3 0 + 'c'), ('%5.2f' % 3.14159).strip(), '%-5s|' % 'ab', '%05d' % -42)
- What is printed? python print(-7 // 2, -7 % 2, -7 // 2 2 + -7 % 2)