ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(f'{0.1:.20f}', f'{1e16:g}', f'{123456789.0:e}', f'{2.5:.0f}', f'{3.5:.0f}')- A. 0.10000000000000000555 1e+16 1.234568e+08 3 3
- B. 0.1 1e16 1.234568e+08 2 4
- C. 0.10000000000000000555 10000000000000000 1.23e+08 2 4
- D. 0.10000000000000000555 1e+16 1.234568e+08 2 4
Correct answer: D. 0.10000000000000000555 1e+16 1.234568e+08 2 4
0.1 is stored as a binary fraction slightly above one tenth, which shows at 20 decimals. The g format switches to exponent form at 1e16, and .0f uses round-half-to-even, so 2.5 gives 2 and 3.5 gives 4.
More Python Programming questions
- What is printed? python n = float('nan') print(n in [n], [n] == [n], n == n, n is n)
- What is printed? python print(sum([0.1, 0.2, 0.3]) == 0.6, 0.1 + 0.2 + 0.3 == 0.6, 0.3 + 0.2 + 0.1 == 0.6)
- What is printed? python print(7.5 // 2, 7.5 % 2, -7.5 // 2, divmod(7.5, -2))
- What is printed? python print(max([('x', 5), ('y', 5)], key=lambda t: t[1]), min([('x', 5), ('y', 5)], key=lambda t: t[1]))
- What is printed? python print(sorted([1.0, True, 1, 0.5, False]))
- What is printed? python try: print(int('10')) except ValueError: print('bad')