ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
nums = [4, 9, 16]
print(list(map(pow, nums, [0.5] * 3)), [n ** 0.5 for n in nums])
  1. A. [2.0, 3.0, 4.0] [2.0, 3.0, 4.0]
  2. B. [2, 3, 4] [2.0, 3.0, 4.0]
  3. C. [2.0, 3.0, 4.0] [2, 3, 4]
  4. D. [0.5, 0.5, 0.5] [2.0, 3.0, 4.0]

Correct answer: A. [2.0, 3.0, 4.0] [2.0, 3.0, 4.0]

Raising to 0.5 gives the square root as a float in both forms, so both lists print with .0 endings. Power with a float exponent always returns a float.

More Python Programming questions

Exams that ask this topic