ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(0.1 * 3 == 0.3, abs(0.1 * 3 - 0.3) < 1e-9)
- A. True True
- B. False True
- C. False False
- D. True False
Correct answer: B. False True
0.1 * 3 is stored as 0.30000000000000004, which differs from 0.3, so the exact comparison fails. The tolerance check passes because the difference is far below 1e-9.
More Python Programming questions
- What is printed? python a = [1, 2, 3] print(a[3:], a[1:10], a[-10:1])
- What is printed? python print(len(bytes('é', 'utf-8')), len('é'))
- What is printed? python print(float('inf') > 10308, -float('inf') < -10308)
- What is printed? python print(sorted({3: 'a', 1: 'b'}), list(reversed(sorted({3: 'a', 1: 'b'}))))
- What is printed? python print('a' < 'B', 'a'.upper() < 'B')
- What is printed? python print(0 == False, 0 is False, '' == None)