ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(0.1 * 10 == 1.0, 0.1 * 10, sum([0.1] * 10) == 1)
- A. False 1.0 True
- B. True 1.0 True
- C. True 0.9999999999999999 True
- D. True 1.0 False
Correct answer: B. True 1.0 True
0.1 * 10 rounds to exactly 1.0 in one multiplication. sum() uses compensated summation since Python 3.12, so the ten additions also land on 1.0.
More Python Programming questions
- What is printed? python print(int(1e15 + 0.3) == 1015, round(1e15 + 0.3) - 1015)
- What is printed? python print(10.01, 0x1F, 1000.0e-3)
- What is printed? python print(str(1e100)[:6], len(str(1e100)), 1e100 == 10100)
- What is printed? python print(divmod(-1, 1020), divmod(1020, -1))
- What is printed? python print(int(1e20) == 1020, int(1e20 + 1) == 1020 + 1, int(1e20) - 1020)
- What is printed? python print(max(float('nan'), 1.0), min(float('nan'), 1.0), max(1.0, float('nan')))