ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(0.1 + 0.1 + 0.1 == 0.3, 0.1 + 0.1 + 0.1, 0.3 == 3 * 0.1)
- A. True 0.3 True
- B. False 0.3 False
- C. False 0.30000000000000004 True
- D. False 0.30000000000000004 False
Correct answer: D. False 0.30000000000000004 False
Adding 0.1 three times gives 0.30000000000000004, which is not the double nearest 0.3. Multiplying 0.1 by 3 gives the same wrong value, so both comparisons are False.
More Python Programming questions
- What is printed? python print(bin(5 ^ 3), bin(-5 & 0b1111), int('-0b101', 2))
- What is printed? python print(2 -1, 2 -1074 > 0, 10 -3 == 0.001, 10 -2)
- What is printed? python print(' '.join(['a', '', 'b']), ' '.join([]) == '', '-'.join('abc'), 'x'.join(['1', '2', '3']))
- What is printed? python from functools import reduce print(reduce(lambda a, b: a + b, ['x', 'y', 'z'], ''), reduce(lambda a, b: a b…
- What is printed? python print(0.1 + 0.2 > 0.3, 0.3 - 0.1 == 0.2, 0.2 + 0.2 == 0.4, 0.4 - 0.2 == 0.2)
- What is printed? python from collections import defaultdict d = defaultdict(int) for w in 'a b a c'.split(): d[w] += 1…