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))
- A. 24 0 2.0 60
- B. 24 1 2.0 60
- C. 24 1 2 60
- 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
- What is printed? python print(2 -1 2 1, 2 -(1 2) 1, (2 -1) (2 1))
- What is printed? python print('%-5s|%5s|' % ('ab', 'cd'), '%(x)d-%(y)s' % {'x': 1, 'y': 'z'})
- What is printed? python print(0.1 3 == 0.30000000000000004, 0.1 3 - 0.3 == 5.551115123125783e-17, 0.3 - 0.1 3 == -5.551115123125783e-17)
- What is printed? python print(len('ab' + 'c' 0), 'ab'[1:][0] 2, ('ab' 2)[::3])
- What is printed? python print(int(' 3 ') + 1, int('3n') 2, float(' 2.5t') 2)
- What is printed? python print(len('é'.encode('utf-8').decode('latin-1')), 'é'.encode('utf-8').decode('latin-1'))