ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(0.1 * 3 == 0.30000000000000004, 0.1 * 3 - 0.3 == 5.551115123125783e-17, 0.3 - 0.1 * 3 == -5.551115123125783e-17)
- A. True True True
- B. False True True
- C. True False True
- D. True True False
Correct answer: A. True True True
0.1 * 3 is the double 0.30000000000000004, and its difference from 0.3 is 5.551115123125783e-17 with that sign. Each check compares exact binary values, so all three are True.
More Python Programming questions
- What is printed? python print(len('ab' + 'c' 0), 'ab'[1:][0] 2, ('ab' 2)[::3])
- What is printed? python print(int(' 3 ') + 1, int('3n') 2, float(' 2.5t') 2)
- What is printed? python print(len('é'.encode('utf-8').decode('latin-1')), 'é'.encode('utf-8').decode('latin-1'))
- What is printed? python print(sum(1 for c in 'Mississippi' if c in 'aeiouAEIOU'), 'Mississippi'.lower().count('s')…
- What is printed? python print([] == [] or 1 / 0, [] and 1 / 0, 0 or 1 and 2)
- What is printed? python print(3 % 2 == 1 and 4 % 2 == 0, 3 // 2 == 1 or 1 / 0)