can someone explain to me why the result is 120? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

8th Mar 2022, 3:04 PM
Game0ver
Game0ver - avatar
4 Answers
+ 9
Subsequent numbers are multiplied: 2*3*4*5
8th Mar 2022, 3:06 PM
Lisa
Lisa - avatar
+ 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
10th Mar 2022, 6:02 AM
SoloilSole
SoloilSole - avatar
0
Thank you so much 🙏
8th Mar 2022, 5:07 PM
Game0ver
Game0ver - avatar
- 1
I reckon the answer is 5! {edit: who downvoted 5 factorial as being the answer???? 5 factorial is written as 5! }
8th Mar 2022, 8:49 PM
HungryTradie
HungryTradie - avatar