ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(0.1 * 0.1 == 0.01, 0.1 * 0.1, round(0.1 * 0.1, 2) == 0.01)
- A. False 0.010000000000000002 True
- B. True 0.01 True
- C. False 0.01 True
- D. False 0.010000000000000002 False
Correct answer: A. False 0.010000000000000002 True
0.1 * 0.1 is not the double nearest 0.01, so the direct comparison is False and the repr shows the extra digits. Rounding to two decimals returns the double for 0.01, so that comparison is True.
More Python Programming questions
- What is printed? python print(int(3.99999999999999999), int(-3.7), 3.99999999999999999 == 4.0, 3)
- What is printed? python s = 'x' 3 print(s -1 == '', s.replace('x', 'xy', 2), s.count('xx'), s.index('x', 1))
- What is printed? python print(' '.join(str(i) for i in range(3)), ','.join(f'{i:02d}' for i in (1, 10)), '|'.join(['x']), ''.join([''…
- What is printed? python print(max(3, 3.0), max(3.0, 3), min(-0.0, 0), min(0, -0.0))
- What is printed? python print('abc'[1:][::-1], 'abc'[::-1][1:], 'abcdef'[::-2][:2])
- What is printed? python print(float('nan') != float('nan'), float('inf') == float('inf'), float('inf') - float('inf') == 0, -float('inf')…