ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
print(max(float('nan'), 1.0), min(float('nan'), 1.0), max(1.0, float('nan')))
  1. A. 1.0 1.0 nan
  2. B. nan 1.0 nan
  3. C. nan nan nan
  4. D. nan nan 1.0

Correct answer: D. nan nan 1.0

max and min keep the current value unless the next item compares greater or smaller. Every comparison with NaN is False, so a NaN in the first position is never replaced, while a NaN in the second position is ignored.

More Python Programming questions

Exams that ask this topic