ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(0.1 + 0.2 > 0.3, round(0.1 + 0.2, 2) == 0.3, 3 * 0.1 == 0.3, 1 / 3 * 3 == 1)
- A. True True False True
- B. False True False True
- C. True True True True
- D. True False False True
Correct answer: A. True True False True
0.1 + 0.2 is slightly above 0.3, and rounding to two places gives exactly 0.3. 3 * 0.1 is not the double for 0.3, but 1 / 3 * 3 rounds back to 1.0.
More Python Programming questions
- What is printed? python print(max([]) if False else 'none', min([5, 2, 8]), sum([]), sum([[1], [2]], []))
- What is printed? python print(float('3.0') == 3, int(float('3.9')), round(3.5) + round(4.5), 3 == 3.0 == 3)
- What is printed? python s = 'abc' 2 print(s.count('a'), s.index('c'), s[2::3], len(s.split('b')))
- What is printed? python print(list(map(len, ['ab', 'c', ''])), list(filter(None, [0, 1, '', 'a'])), any([]), all([]))
- What is printed? python print('%d items' % 3, '%s' % 3.0, '%s' % None, '%r' % None)
- What is printed? python print(10 3 == 1000.0, 1e3 == 10 3, type(10 3).name, type(1e3).name)