ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from functools import reduce print(reduce(lambda a, b: a * b, range(1, 21), 1), reduce(lambda a, b: a + b, [], 0))
- A. 2432902008176640001 0
- B. 1216451004088320000 0
- C. 2432902008176640000 0
- D. 2432902008176640000 None
Correct answer: C. 2432902008176640000 0
reduce with initial value 1 multiplies 1 through 20, which gives 20! = 2432902008176640000. Reducing an empty iterable returns the initial value 0.
More Python Programming questions
- What is printed? python try: print(sorted([3, None, 1])) except TypeError as e: print(e)
- What is printed? python def flat(x): for y in x: if isinstance(y, list): yield from flat(y) else: yield y print(list(flat([1, [2, [3…
- What is printed? python print(len(str(int('7' 4300)))) try: int('7' 4301) except ValueError: print('no')
- What is printed? python print(round(0.25, 1), round(0.35, 1), round(2.5), round(-0.5))
- What is printed? python d = {'a': 1, 'b': 2} d['a'] = 3 d.pop('a') d['a'] = 4 print(list(d.items()))
- What is printed? python print({k % 4: k k for k in range(9, -1, -1)})