ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
from math import prod
print(prod([2, 3, 4]), prod([]), prod([0.5, 4]), prod(range(1, 4), start=10))
  1. A. 24 0 2.0 60
  2. B. 24 1 2.0 60
  3. C. 24 1 2 60
  4. D. 24 1 2.0 6

Correct answer: B. 24 1 2.0 60

prod multiplies the items, and the product of an empty iterable is 1. Multiplying 0.5 by 4 gives the float 2.0, and start=10 scales the product of 1, 2 and 3 to 60.

More Python Programming questions

Exams that ask this topic