+ 5
can someone explain to me why the result is 120?
from functools import reduce mul = lambda n1, n2: n1 * n2 class cls: def __enter__(self): def f(n): return reduce(mul, range(2, n + 1), 1) return f def __exit__(self, *args): pass with cls() as a: print(a(5)) 120
4 Answers
+ 9
Subsequent numbers are multiplied: 2*3*4*5
+ 4
Hi Game0ver
range(2, n+1) --> range(2, 6) which is 2, 3, 4, 5 and here we will multiply them in 1 step which means without skip any of this number. So the result 2*3*4*5 = 120
0
Thank you so much đ
- 1
I reckon the answer is 5!
{edit: who downvoted 5 factorial as being the answer???? 5 factorial is written as 5! }