ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
print(f'{0.1 + 0.2:.17g}', f'{1/7:.10f}', f'{100/3:.0f}', f'{2.345:.2f}')
  1. A. 0.3 0.1428571429 33 2.35
  2. B. 0.30000000000000004 0.1428571429 33 2.35
  3. C. 0.30000000000000004 0.142857 33 2.35
  4. D. 0.30000000000000004 0.1428571429 33 2.34

Correct answer: B. 0.30000000000000004 0.1428571429 33 2.35

Seventeen significant digits reveal the binary error in 0.1 + 0.2. 2.345 is stored slightly above the midpoint, so it rounds up to 2.35 at two places.

More Python Programming questions

Exams that ask this topic