ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
print(0.1 + 0.2 == 0.30000000000000004, 0.1 + 0.2 - 0.30000000000000004 == 0, '%.20f' % (0.1 + 0.2))
- A. False True 0.30000000000000004441
- B. True True 0.30000000000000004441
- C. True False 0.30000000000000004441
- D. True True 0.30000000000000004
Correct answer: B. True True 0.30000000000000004441
The literal 0.30000000000000004 is the same double as 0.1 + 0.2, so the first two comparisons are True. Printing with 20 decimals shows the exact stored value, which has more digits than the shortest repr.
More Python Programming questions
- What is printed? python s = '42' print(s 2 + '!' if s.isdigit() else '', int(s) 2, s.zfill(4) + '|' + s.rjust(4, '0') + '|' + s.ljust(4…
- What is printed? python print(sum(map(int, '123456789')) == 45, sum(map(int, str(99))), 99 % 9)
- What is printed? python print('a' 3 < 'b', 'a' 3 < 'aa', 'aaa' > 'aab', 'aa' + 'b' > 'aab')
- What is printed? python x = 5 print(x // 2 2 == x, x / 2 2 == x, 5 / 2 == 2.5, 5 // 2.0 == 2)
- What is printed? python print(bytes('é', 'utf-8'), 'é'.encode('latin-1'), len('é'.encode('latin-1')) == len('é'.encode('utf-8')))
- What is printed? python print(round(-0.5), round(0.5), round(1.5), round(-1.5), round(2.5))