ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(0.5 == 1/2, 0.1 + 0.4 == 0.5, 0.25 + 0.25 == 0.5, 0.7 + 0.1 == 0.8)
- A. True True True True
- B. True True True False
- C. True False True False
- D. False True True False
Correct answer: B. True True True False
0.5 and 0.25 are exact in binary, and 0.1 + 0.4 rounds to exactly 0.5. 0.7 + 0.1 is 0.7999999999999999, which is not the double for 0.8.
More Python Programming questions
- What is printed? python x = 255 print(x.tobytes(2, 'little'), int.frombytes(b'x01x02', 'little'), (258).tobytes(2, 'big').hex())
- What is printed? python print(len(str(10100 - 1)), str(105)[:3], int('9' 50) % 9)
- What is printed? python print(round(1234.5678, -2), round(1234.5678, 2), round(-0.0001, 3), round(5.5), round(6.5))
- What is printed? python print(7.0 == 7, (7.0).isinteger(), (7.5).isinteger(), 1e3 == 1000)
- What is printed? python print(2 0.5 2 0.5 == 2, (2 0.5) 2, 2 0.5 2)
- What is printed? python print('%.2f' % 1.005, '%.2f' % 1.015, '%.2f' % 1.025, '%.1f' % 0.25)