ProgrammingHardProduct-company MCQ pattern
What is the largest float that is less than 1.0 in Python, as printed by repr?
- A. 0.9999999999999999
- B. 0.999999999999999
- C. 0.99999999999999
- D. 1.0
Correct answer: A. 0.9999999999999999
The largest double below 1.0 is 1 - 2**-53, and its shortest round-trip repr has 16 nines. Literals with 17 nines round to 1.0, so they are not below one.
More Python Programming questions
- What is printed? python print(3 // 2 2 + 3 % 2, -3 // 2 2 + -3 % 2)
- What is printed? python print('%s and %r' % ('a', 'a'))
- What is printed? python print('-'.join(map(str, range(3, 0, -1))))
- What is printed? python print('abc'[-1:-4:-1], 'abc'[5:], 'abc'[-10:2])
- What is printed? python print(ord('A') + 1, chr(ord('a') - 32))
- What is printed? python print(divmod(7, -2), 7 % -2)