ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print('%.2f' % 0.125, '%.2f' % 0.375, '%.1f' % 0.05, '%.0f' % 1.5)- A. 0.13 0.38 0.1 2
- B. 0.12 0.37 0.1 2
- C. 0.12 0.38 0.1 2
- D. 0.12 0.38 0.0 2
Correct answer: C. 0.12 0.38 0.1 2
0.125 and 0.375 are exact binary fractions sitting on a tie, so round-half-to-even gives 0.12 and 0.38. 0.05 is stored slightly above its decimal value, so it rounds up to 0.1.
More Python Programming questions
- What is printed? python print(-17 % -5, 17 % -5, -17 % 5, -(17 % 5))
- What is printed? python a = 'ab' b = a 3 print(b.count('ab'), b.count('aba'), len(b.split('b')))
- What is printed? python print(0.1 10 == 1.0, 0.1 10, sum([0.1] 10) == 1)
- What is printed? python print(int(1e15 + 0.3) == 1015, round(1e15 + 0.3) - 1015)
- What is printed? python print(10.01, 0x1F, 1000.0e-3)
- What is printed? python print(str(1e100)[:6], len(str(1e100)), 1e100 == 10100)