ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
print(f'{0.1:.20f}'[:12], f'{2/3:.3f}', f'{1e22:.0f}', f'{1e23:.0f}')
  1. A. 0.1000000000 0.667 10000000000000000000000 100000000000000000000000
  2. B. 0.1000000000 0.667 10000000000000000000000 99999999999999991611392
  3. C. 0.1000000000 0.666 10000000000000000000000 99999999999999991611392
  4. D. 0.1000000000 0.667 1e+22 100000000000000000000000

Correct answer: B. 0.1000000000 0.667 10000000000000000000000 99999999999999991611392

Formatting with .0f shows the exact value stored in the double. 1e22 is exact, but 1e23 is stored as 99999999999999991611392, so the printed digits differ from the decimal you typed.

More Python Programming questions

Exams that ask this topic