ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(float('1e3') == 1000, float('1E-2') * 100, float(' .5 '), float('5.'))
  1. A. True 0.01 0.5 5.0
  2. B. True 1.0 0.25 5.0
  3. C. True 1.0 0.5 5.0
  4. D. True 1.0 0.5 5

Correct answer: C. True 1.0 0.5 5.0

float accepts a bare leading dot, a trailing dot, an upper-case E and surrounding spaces. 0.01 * 100 happens to round to exactly 1.0 in binary.

More Python Programming questions

Exams that ask this topic